how to store values in csv format?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Voss
le 27 Mar 2022
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 commentaires
Voss
le 27 Mar 2022
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);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!