Cells to csv files
Afficher commentaires plus anciens
I have 1by3 cell as below.
'NSF4_TTD_55''NSF4_TTD_56''NSF4_TTD_57'
I want to write to csv file as such without hyphens like
column1 column2 column3 NSF4_TTD_55 NSF4_TTD_56 NSF4_TTD_57
Can anyone please help how can write them into csv file.
when i use csvwrite('filename.csv',filename);
it is splitting every letter (or character or symbol_ etc) into a separate column
please help how can I write in to csv file as 1-row and 3-column form
Thanks in advance,
Réponses (1)
Geoff Hayes
le 8 Nov 2014
Mekala - according to the documentation at csvwrite, cell arrays are not accepted as inputs to the function. If you want to write cell data to file, please see export cell data to file where you will use fprintf. In your case, this would be something like
% data to write to file
cellArray = {'NSF4_TTD_55','NSF4_TTD_56','NSF4_TTD_57'};
% open the file for writing
fid = fopen('filename.csv','wt+');
if fid>0
% write each column to file
numCols = length(cellArray); % assumes that cellArray is row vector
for k=1:numCols
if k==numCols
fprintf(fid,'%s\n',cellArray{k});
else
fprintf(fid,'%s,',cellArray{k});
end
end
fclose(fid);
end
Try the above and see what happens!
Catégories
En savoir plus sur Workspace Variables and MAT Files dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!