how to write this data into a text file?

1 回表示 (過去 30 日間)
chocho
chocho 2018 年 5 月 23 日
コメント済み: KSSV 2018 年 5 月 23 日
Hello guys, I have written this data into a text file by the format of this textfile has a wrong format
[rowstg2,colstg2]=size(Stage2_size);
fid2= fopen('Stage2_infor.txt','wt');
for g2=1:rowstg2
for g3=1:colstg2
fprintf(fid2,'%s\t%d',Stage2_size{g2,g3});
end
fprintf(fid2,'\n');
end
fclose(fid2);
out_textfile
  1 件のコメント
chocho
chocho 2018 年 5 月 23 日
Any help plz?

サインインしてコメントする。

採用された回答

KSSV
KSSV 2018 年 5 月 23 日
See this example:
Name = {'Tom' ; 'Dick' ; 'Harry' } ;
Weight = [50 60 55] ;
Age = [25 24 26] ;
fid= fopen('data.txt','w') ;
for i = 1:length(Name)
fprintf(fid,'%s %s %d\n',Name{i},num2str(Weight(i)),Age(i)) ;
end
fclose(fid) ;
  4 件のコメント
chocho
chocho 2018 年 5 月 23 日
KSSV
KSSV 2018 年 5 月 23 日
The code I gave works very fine, with few minimal changes.
S = load('stage2_size.mat') ;
S = S.Stage2_size ;
fid= fopen('data.txt','w') ;
for i = 1:size(S,1)
fprintf(fid,'%s %s %d\n',S{i,1},S{i,2},S{i,3}) ;
end
fclose(fid) ;

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by