フィルターのクリア

how to store values in csv format?

3 ビュー (過去 30 日間)
ramya
ramya 2022 年 3 月 27 日
コメント済み: Voss 2022 年 3 月 27 日
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?

採用された回答

Voss
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 件のコメント
ramya
ramya 2022 年 3 月 27 日
Sorry sir , but i am not able to understand...
Voss
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 ExchangeText Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by