Good afternoon.
I want to write a numbers of vectors to txt in a loop using dlmwrite. For example:
for n=1:a
x=(1,n,3)
...
dlmwrite('abc_n_y.txt',x,...)
the vector is updating everytime and replace the previous value in each loop while I hope that the name of the .txt will also update in each loop otherwise the old .txt will be replaced by the new one. But in this case the n in 'abc_n_y.txt' is obviously be treated as a character rather than a variable. Can anyone gives some help to me?
Many thanks!

 採用された回答

madhan ravi
madhan ravi 2018 年 11 月 18 日
編集済み: madhan ravi 2018 年 11 月 18 日

0 投票

This is efficient than writing in a loop:
x=cell(1,a);
for n=1:a
x{n}=[1,n,3];
end
x=[x{:}];
dlmwrite('abc_n_y.txt',x,'delimiter',' ')
for n=1:a
x=[1,n,3];
filename=sprintf('abc_%d_y.txt',n)
dlmwrite(filename,x,'delimiter',' ')
end

2 件のコメント

Hok Lim Chan
Hok Lim Chan 2018 年 11 月 18 日
Thank you my friend, it works pretty well!!!
madhan ravi
madhan ravi 2018 年 11 月 18 日
Your most welcome :)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2018 年 11 月 18 日

コメント済み:

2018 年 11 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by