How to print data from cell array to a text file ?

조회 수: 6 (최근 30일)
RAJ
RAJ 2019년 11월 27일
댓글: RAJ 2019년 11월 27일
Dear programmers
I have a cell array(FINALSHEET) as provided in the image file. I need to write the contents of FINALSHEET{1,1} (which is having only integer values) and FINALSHEET{1,2}( which is having only floating values) in a text file say, matlab_data.txt. I have tried a code as shown below but it concetanates both FINALSHEET{1,1} and FINALSHEET{1,2}. Please help.
FINALSHEET= { diffusion{1,1}{1,1}, YMF};
fid = fopen('matlab_data.txt','w');
for row = 1:1:16356
fprintf(fid ,'%d %f \n', FINALSHEET{1,1}{row,:},FINALSHEET{1,2}{row,:});
end
fclose(fid)

채택된 답변

Marcel Kreuzberg
Marcel Kreuzberg 2019년 11월 27일
try
fprintf(fid ,'%d %f \r\n', FINALSHEET{1,1}{row,:},FINALSHEET{1,2}{row,:});
  댓글 수: 1
RAJ
RAJ 2019년 11월 27일
Thank you Mr. Marcel. I have written the code in a different way. This one also worked.
SHEET_2= { diffusion{1,1}{1,1}, YMF};
SHEET_3=num2cell(SHEET_2{1,1});
SHEET_4={SHEET_3,YMF};
FINALSHEET = cat(2, SHEET_4{:});
fid = fopen('matlab_data.txt','w');
[nrows,ncols] = size(FINALSHEET);
for row = 1:1:nrows
fprintf(fid ,'%d %f \n', FINALSHEET{row,:});
end
fclose(fid)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by