How to write csv data in row?

1 Ansicht (letzte 30 Tage)
Rohit Bhoi
Rohit Bhoi am 1 Mär. 2016
Beantwortet: Walter Roberson am 2 Mär. 2016
I have two string vectors how to write them in row in csv?
I am using following code
A ={'text1','text2', 'text3', 'text4', 'text5'}; %'
%***************************************************************************
%write string to csv
[rows, columns] = size(A);
for index = 1:rows
fprintf(fileID, '%s,', A{index,1:end-1});
fprintf(fileID, '%s\n', A{index,end});
end
fclose(fileID);
where shall I modified it?

Antworten (1)

Walter Roberson
Walter Roberson am 2 Mär. 2016
That should work. Another way is:
cols = size(A,2);
fmt = [repmat('%s,', 1, cols - 1), '%s\n'];
Atrans = A.'; %need to transpose it
fprintf(fileID, fmt, Atrans{:});
with no loop.

Kategorien

Mehr zu Text Analytics Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by