write table to .xls document with variable (cell array) not splitting into different cells
5 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am having some trouble with writetable into a .xls document and would like to ask for your help.
I have a table A with many variables as below.
A = [Case Load_Type elements X1 PX1 PY1 PZ1 X2 PX2 PY2 PZ2 glob np relative al be ga memo]
Please see pic below and find the table attached.

when I write it to excel I use
writetable(A,'Table.xls','Sheet',1,'Range','A1')
All cells are correctly written except for elements which uses a single separate cell ,column for each number.

I would like to get all elements into one cell as below

How could I define the elements column in matlab so that it keeps all numbers for each single (row,column) separated by a space and in the same cell when writing table to .xls?
Thank you in advance.
2 件のコメント
Guillaume
2019 年 7 月 26 日
Excel does not support having several numbers in the same cell, hence matlab distributes the numbers in contiguous cells.
The alternative is converting the numbers to text and concatenate the textual representations with a suitable separator (space?, comma?) so that they can be written into the same cell. The value of that is dubious since excel will treat the content of the cells as text so won't be able to perform any useful calculation on them.
If that's what you want, it can be done easily but this is just using a complicated program (excel) as just a basic viewer for tabular data. You my as well write the table as a text file.
採用された回答
Guillaume
2019 年 7 月 26 日
編集済み: Guillaume
2019 年 7 月 26 日
You can convert your elements column into text with:
A.elements = cellfun(@num2str, A.elements, 'UniformOutput', false);
If you want to better control the separator (num2str may put too much space if the numbers are not integer):
separator = ' '; %or ',', or whatever you want
A.elements = cellfun(@(v) strjoin(arrayfun(@num2str, v, 'UniformOutput', false), separator), A.elements, 'UniformOutput', false);
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!