How to write csv data in row?

조회 수: 8 (최근 30일)
Rohit Bhoi
Rohit Bhoi 2016년 3월 1일
답변: Walter Roberson 2016년 3월 2일
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?

답변 (1개)

Walter Roberson
Walter Roberson 2016년 3월 2일
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.

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by