Copy results from a .mat file to existing excel file
6 views (last 30 days)
Show older comments
Hello, I have a .mat file (please check the attached script which produces it) as an output and I want to export the results into an existing excel sheet. Run1 and Run2 in the image are the results from previous simulations which are saved in .mat file everytime i run my script. I entered those 2 manually and I can't find a way to export by writing a script. The case names and number of outputs are same everytime, only the output changes. Thank you very much for your help. (Matlab version: R2018b)
2 Comments
Maximilian Panzik
on 17 Sep 2020
Hi there,
as I understand you need to continue an excel file, that is already populated.
So first you need to know, where to continue, so find out the size of the exising data:
[num,txt,raw] = xlsread(filename);
[rowN,colN] = size(raw);
You now have to define, where you start to write your data in the format 'A1'. If your max column is Z, you could use
range = [char(colN + 1 + 64),'1'];
Format your data in an array that equals your export format and use
xlswrite(filename,data,sheetName,range);
to write to your excel file.
Accepted Answer
Maximilian Panzik
on 18 Sep 2020
You can use struct2array
sz = size(testSetup,2);
arrSz = sz*4;
exportArr=[];
for i = 1:sz
str = struct2array(testSetup(i).evaluation);
data = struct2array(str);
exportArr = [exportArr;nan;data']
end
This creates an array in the format of the data columns in your excel file.
1 Comment
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!