フィルターのクリア

How write a struct into a text file?

7 ビュー (過去 30 日間)
Donghui  Sun
Donghui Sun 2013 年 12 月 12 日
コメント済み: Donghui Sun 2013 年 12 月 12 日
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 日
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 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by