How do I create an excel file from a cell array that actually displays all the information in each colum?
2 views (last 30 days)
Show older comments
Hi all,
I have a 1X4 cell array (called result), where each colum contains one 3X1 cell array containing one numeric variable and two datenum variables. I was wondering how I can export these data to an excel file to simply be a 3-row-by-4-colum spreadsheet? I tried:
T=cell2table(result);
writetable(T, "result.xlsx")
but the resulting file result.xlsx is simply a 1x4 sheet containing 'result1', 'result2', 'result3', and 'result4'. How can I get the 3-row-by-4-colum spreadsheet output?
0 Comments
Answers (1)
Bob Thompson
on 6 Mar 2019
I would suggest reformatting your data first, so that you have everything in the upper level of cells.
for i = 1:size(result)
results{:,i} = result{i};
end
Then you should just be able to use the excel writer to output this.
xlswrite('result.xlsx',results);
3 Comments
Bob Thompson
on 7 Mar 2019
Hmm, I tried doing result = [result{:}]; and a I got 1x12. Although, now that I think about it, my internal arrays were 1x3 instead of 3x1. Is that the difference?
Guillaume
on 7 Mar 2019
Well, yes. If you horizontally concatenate four 1x3 arrays you get a 1x12 array. If you horizontally concatenate for 3x1 arrays you get a 3x4 array.
If the arrays were 1x3, then
vertcat(result{:}).'
would be the way to go.
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!