How to export mulitple 1xN row matrix into the csv
조회 수: 1 (최근 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.

댓글 수: 0
답변 (1개)
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');
댓글 수: 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!