how to store values in csv format?
조회 수: 3 (최근 30일)
이전 댓글 표시
I have 1x500 matrix with doubles. I want to save it in a CSV file format
matrix=[a,b,c,d ,data];
dlmwrite('matrix.csv',matrix,'-append',delimiter,',') %saving data
the data is getting saved in excel sheet from 2nd row .
is there any way to save data from first cell of excel sheet?
댓글 수: 0
채택된 답변
Voss
2022년 3월 27일
Maybe try it without the '-append' option (and ',' is the default delimiter, so you don't need to specify it [and 'delimiter' needed to be in quotes anyway]):
dlmwrite('matrix.csv',matrix)
Also note that the documentation for dlmwrite recommends using writematrix instead.
댓글 수: 4
Voss
2022년 3월 27일
Your code might look like this (Option 1 above):
% you have a 1x500 matrix with doubles, called matrix
dlmwrite('matrix.csv',matrix); % write it. this is the first row
for ii = 2:N_rows % for the remaining rows
matrix = randn(1,500); % you get the next 1x500 row of numbers somehow
dlmwrite('matrix.csv',matrix,'-append'); % write it, appending to what's already in the file
end
Or your code might look like this (Option 2 above):
% you have a 1x500 matrix with doubles, called matrix
% build another matrix that will contian all the rows, call it all_matrix
all_matrix = matrix; % at first, it only has the first row
for ii = 2:N_rows % for the remaining rows
matrix = randn(1,500); % you get the next 1x500 row of numbers somehow
all_matrix(end+1,:) = matrix; % and add the new row to the end of all_matrix
end
% now that all_matrix has all the rows, write it to file:
dlmwrite('matrix.csv',matrix);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!