In: Computer Science
I am writing a matlab program where I created a figure that has a few different elements to it and now I need to move that figure into a specific excel file into a specific set of boxes in the excel file. With numbers and text I have always used the xlswrite function for this in order to put data into specific boxes. How do I do the same with this figure? The figure I have is called like this:
scatter(x3,y3)
hold on
plot(x1,y1,x2,y2)
hold off
With all these lines how do I treat it like one function in order to move it to excel?
try xlApp = actxGetRunningServer('Excel.Application'); % capture existing excel application catch ME %#ok xlApp = actxserver('Excel.Application'); % instantiate new excel application end xlApp.Visible = 1; xlWorkbook = xlApp.workbooks.Open(fullfile(xlFilePath,xlFileName),0,true); xlSheets = xlWorkbook.Sheets; xlSheetNamesArray = cell(xlSheets.Count,1); for i = 1:xlSheets.Count xlSheetNamesArray{i} = xlSheets.Item(i).Name; % sheet-order is not guaranteed so must build array end [~,idx] = ismember('Price',xlSheetNamesArray); xlSheets.Item(idx).Activate xlActiveSheet = xlWorkbook.ActiveSheet; xlCurrRange = xlActiveSheet.Range('C4:C33'); priceVector = xlCurrRange.Value2; priceVector = cell2mat(priceVector); [~,idx] = ismember('Portfolios',xlSheetNamesArray); xlSheets.Item(idx).Activate xlActiveSheet = xlWorkbook.ActiveSheet; xlCurrRange = xlActiveSheet.Range('B4:B22'); isinVector = xlCurrRange.Value2; xlCurrRange = xlActiveSheet.Range('C3:G3'); ptfNumVector = cell2mat(xlCurrRange.Value2)'; xlCurrRange = xlActiveSheet.Range('C4:G22'); dataMatrix = xlCurrRange.Value2; isnanMatrixMask = strcmp(dataMatrix,'ActiveX VT_ERROR: '); % handle missing data - assume as no position dataMatrix(isnanMatrixMask) = {0}; dataMatrix = cell2mat(dataMatrix);