- "save each column of the sample matrix in a separate .csv file"   e.g. Channel01, Channel02, etc.
- "how to give each filename an index"   make the number part of the name, e.g. sprintf('Channel%02d.csv',jj). The leading zero, "0", makes the files appear in the "correct" order in file listings.
- I prefer fprintf over save to write text
Save each column of a matrix in a seperate .csv file
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
monmatlab
el 22 de Dic. de 2016
Comentada: monmatlab
el 3 de En. de 2017
I was wondering how to write this code in a more elegant way. Basically, I want to save each column of the sample matrix in a separate .csv file. I wanted do this in a for loop, but it is not clear for me how to give each filename an index, because Channel(i).csv ,is just considered to be the filename without index
channel1=sample(:,1);save Channel1.csv channel1 -ASCII;
channel2=sample(:,2);save Channel1.csv channel2 -ASCII;
channel3=sample(:,3);save Channel1.csv channel3 -ASCII;
channel4=sample(:,4);save Channel1.csv channel4 -ASCII;
channel5=sample(:,5);save Channel1.csv channel5 -ASCII;
channel6=sample(:,6);save Channel1.csv channel6 -ASCII;
...
...
....
channel15=sample(:,15);save Channel1.csv channel15 -ASCII;
channel16=sample(:,16);save Channel1.csv channel16 -ASCII;
0 comentarios
Respuesta aceptada
per isakson
el 22 de Dic. de 2016
Editada: per isakson
el 22 de Dic. de 2016
sample = [ magic(6); magic(6) ]; % Create sample data
len = size( sample, 2 );
folder = 'h:\m\cssm';
for jj = 1 : len
ffs = fullfile( folder, sprintf('Channel%02d.csv',jj) );
fid = fopen( ffs, 'w' );
fprintf( fid, '%f\n', sample(:,jj) );
fclose( fid );
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!