How to export mulitple 1xN row matrix into the csv

2 次查看(过去 30 天)
I have a mat file that has some variables each of size 1XN. I want to export all the variables to the csv.
Say I have 20 variables with size 1X50 in the mat file. Then the mat file has to be loaded and each variable has to be written into csv file.The generated csv file should be like:
1. Each variable name is mentioned in the first row and into separate column, like col1 = var1, col2 = var2..
2. Under each variable name should contain all the 50 data items.
I have attached the sample template of how the data should come. Thanks.

回答(1 个)

KL
KL 2017-11-5
编辑:KL 2017-11-5
Just create a table and use write table,
t = array2table([A.', B.']);
writetable(t,filename);
or concatenate them and use csvwrite or dlmwrite as shown here: https://de.mathworks.com/matlabcentral/answers/259937-csvwrite-a-matrix-with-header,
varNames = {'A','B'};
fid = fopen(filename,'w');
fprintf(fid,'%s\n',varNames)
fclose(fid)
dlmwrite(filename,[A.', B.'],'-append');

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by