How to combine multi column cell in table with commas for excel?

8 次查看(过去 30 天)
Hi, I have made a table in Matlab with various columns. Some cells of the table (for example for columns A and B) have multiple columns.
When I export this to excel it divides these up and gives me a format of columns with A_1,A_2,A_3 etc.
The data is actually a triplet of datapoints, so I want to combine the data for A into one column by using commas as a deliminator.
So for example, get an output with the first row of column A saying 33.08,24.23,5.0506
I assume I somehow need to combine the datapoints with commas before creating the table.
Is there any way to do this?
Thank you very much,
Eva

回答(1 个)

Navya Seelam
Navya Seelam 2020-2-21
You can try creating table from string array rather than numeric array to combine the data for A into one column as shown below
A=[133.08 24.23 5.0506;114.65 -33.555 12.999];
Astr=num2str(A,'%5f,');
T=table(Astr(:,1:end-1));
writetable(T,'data.xlsx');
Please refer to this link to understand the inputs arguments to num2str.

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by