Write 2d matrix to single Excel cell
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bastian Kindereit
am 21 Mär. 2022
Kommentiert: Voss
am 22 Mär. 2022
I need to make an Excel file (or CSV) with a list of variable names in the first column (e.g. attached "Nm.mat" file), and their respective value in the second column. The values are a mix of scalars and matrices (e.g. attached "Val.mat" file). I used the following command to generate the csv file after loading Nm and Val to the workspace:
>> writetable(table(Nm,Val),'test.csv','WriteVariableNames',false);
Unfortunately, it writes all the values from the 12x12 matrix in a long row array with one value per cell (see "test_is.csv"). I would like it to arrange them all into a single cell as in the "test_shouldbe.csv" file.
Please help me generate the "test_shouldbe.csv" file. It's fine if it writes it to an Excel instead as that's ultimately what it's going to be. Thanks in advance!
0 Kommentare
Akzeptierte Antwort
Voss
am 21 Mär. 2022
load('Nm.mat');
load('Val.mat');
t = table(Nm,Val);
% make a cell array containing the table's contents
C = table2cell(t);
% convert the second column to character vectors representing the matrices
C(:,2) = cellfun(@mat2str,C(:,2),'UniformOutput',false)
% write the cell array to file
writecell(C,'test_shouldbe.csv');
4 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!