export numeric array to ASCII file using save

109 ビュー (過去 30 日間)
Phong Pham
Phong Pham 2016 年 4 月 6 日
コメント済み: Guillaume 2016 年 4 月 6 日
Hi everyone
I want to export matlab data ASCII file. I used save my_data.out A -ASCII and it worked fine. Note that my_data.out is the name of file after converting. The problem that I faced off is that i have multiple file names to convert to .out and i want to have different file names like my_data_1.out, my_data2.out (it is more than 1200 files). I don't want to manually do it one by one.
is there a way to do it? Please helps. Thanks

採用された回答

Guillaume
Guillaume 2016 年 4 月 6 日
編集済み: Guillaume 2016 年 4 月 6 日
Of course, there's a way to do it. Computers are particularly good at repeating the same task over and over.
It's not clear what variable you want to export to these 1200 or more files. Assuming you have a loop that creates a different A 1200 times
for fileidx = 1:1200
A = somefunctionthatcreateA();
save(sprintf('my_data_%04d.out', fileidx), 'A', '-ascii');
end
The important bit is the sprintf call to create the file name dynamically. The %04d in the formatspec converts the file index into a number string of 4 digits padded with zeros if necessary.
  2 件のコメント
Phong Pham
Phong Pham 2016 年 4 月 6 日
Thank you. It works out if you put "'" between A also.
Guillaume
Guillaume 2016 年 4 月 6 日
Oh, yes, sorry about this.

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

その他の回答 (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