write table to .xls document with variable (cell array) not splitting into different cells
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ana Bermejo Jimenez
am 26 Jul. 2019
Bearbeitet: Guillaume
am 26 Jul. 2019
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 Kommentare
Guillaume
am 26 Jul. 2019
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.
Akzeptierte Antwort
Guillaume
am 26 Jul. 2019
Bearbeitet: Guillaume
am 26 Jul. 2019
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!