how to import the output of a function displayed
Show older comments
How do one import the output of a function simulated in MATLAB 2015 that is about 250 number outputs displayed vertically. I need to put it into MSexcel for further analysis.
1 Comment
Accepted Answer
More Answers (2)
Marco
on 5 Oct 2017
2 votes
Hello, to export a table in the workspace to a Microsoft® Excel® spreadsheet file, use the writetable function. You can export data from the workspace to any worksheet in the file, and to any location within that worksheet.
You can see the documentation at this link: https://it.mathworks.com/help/matlab/import_export/exporting-to-excel-spreadsheets.html BR Marco
Walter Roberson
on 5 Oct 2017
2 votes
Assign the output to a variable if possible.
If the output is just be displayed, such as through disp() or fprintf(), then best is to modify the function to return the information.
If it is just being displayed and modifying the function is not practical, then use evalc() to capture the output as text, after which you can split it into lines and str2double() it.
2 Comments
segun
on 5 Oct 2017
Walter Roberson
on 5 Oct 2017
Example:
S = evalc('MyBlackBoxFunction()');
Slines = regexp(S, '\n', 'split');
Slines(1:3) = []; %remove a text header
Slines( cellfun(@isempty, Slines) ) = []; %delete empty lines
data = str2double(Slines);
xlswrite('MyOutput.xlsx', data);
Categories
Find more on Spreadsheets in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!