Cells to csv files

3 ビュー (過去 30 日間)
Mekala balaji
Mekala balaji 2014 年 11 月 8 日
回答済み: Geoff Hayes 2014 年 11 月 8 日
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,

回答 (1 件)

Geoff Hayes
Geoff Hayes 2014 年 11 月 8 日
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!

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by