How to save multiple tables in seperate sheets in Excel

66 ビュー (過去 30 日間)
Victoria
Victoria 2018 年 7 月 13 日
コメント済み: Benjamin Drewry 2019 年 12 月 2 日
Hello - I am running multiple files in MATLAB and would like to save the outputs from regionprops into one large Excel file. With my current code, which is below, it will only save as seperate .txt files. Help is appreciatied - thank you!
figure,imshow(BW);
stats = regionprops(BW,'MajorAxisLength');
t = struct2table(stats);
path = 'C:\Users\Test' ;
filename = [path, filesep, 'GFP',num2str(k)] ;
writetable(t,filename);
end
k stands for k=1:length(Files)
  1 件のコメント
Benjamin Drewry
Benjamin Drewry 2019 年 12 月 2 日
Victoria,
Just use the writetable function with the name-value pair 'Sheet', number.
i.e. writetable(t, 'fName.xlsx', 'Sheet', 4);
Thanks,
Ben

サインインしてコメントする。

回答 (2 件)

Christopher Wallace
Christopher Wallace 2018 年 7 月 13 日
Hi Victoria,
Have you looked into the documentation for the Matlab command 'xlswrite' ?
https://www.mathworks.com/help/matlab/ref/xlswrite.html
?
You should be able to do something along the lines of:
xlswrite(filename, data, 'Sheet1')
But since the xlswrite function only accepts two-dimensional numeric, character array, or string array, or, if each cell contains a single element, a cell array, you'll have to reformat your data before putting it in.
?
If you'd like to add a new sheet just change the name of the sheet in the xlswrite parameters. If it the sheet doesn't exist it will be created.
?
Best Regards,
Chris
  9 件のコメント
Victoria
Victoria 2018 年 7 月 13 日
I got this error when I tried that:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
And yes, Major Axis Length is the only one I'd like right now.
Thanks for the help
Christopher Wallace
Christopher Wallace 2018 年 7 月 13 日
Can you post the full code?

サインインしてコメントする。


Peter Perkins
Peter Perkins 2018 年 8 月 3 日
Victoria, I really recommend that you not use xlswrite. As Paolo suggests, writetable can definitely write to sheets in an Excel file.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by