I have a 100-by-1 struct array, named fInfo. fInfo have four fields:a1,a2,a3,a4. For example, the fInfo(1,1) is
fInfo(1,1).a1 = [89 78 90 56];
fInfo(1,1).a2 = 100
fInfo(1,1).a3 = 20
fInfo(1,1).a4 = 'small'
What should I do to write the struct into a text file? I have tried this:
fid = fopen('result.txt', 'wt+');
for i = 1:size(fInfo, 1)
fprintf(fid, '%s\t %d\t %d\t %s\n',fInfo(i,1).a1,fInfo(i,1).a2,fInfo(i,1).a3,fInfo(i,1).a4,);
end
fclose(fid);
But,it not works.
Any suggestions?

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 12일

0 개 추천

fid = fopen('result.txt', 'wt+');
for i = 1:size(fInfo, 1)
fprintf(fid, '%d\t',fInfo(i,1).a1),
fprintf(fid, '%d\t',fInfo(i,1).a2)
fprintf(fid, '%d\t',fInfo(i,1).a3)
fprintf(fid, '%s\n',fInfo(i,1).a4)
end
fclose(fid);

댓글 수: 1

Donghui  Sun
Donghui Sun 2013년 12월 12일
Thanks, It works. I find another way. Firstly, transform the a1 to string,and then use the fprintf. :-)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

질문:

2013년 12월 12일

댓글:

2013년 12월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by