Loading in a for loop

3 ビュー (過去 30 日間)
Tim Johansson
Tim Johansson 2020 年 10 月 15 日
コメント済み: Tim Johansson 2020 年 10 月 16 日
im in a situation on which i have to load a lot of files (about 400) and was wondering if there were a smart way to do it.
I was thinking that a for loop was the best way to do it, but the for loop does not recognise the 'i' as the variable.
for i=1:400
run_i='C:\Users\unknown\run_i'
end
is there a simple way to solve this?
  2 件のコメント
Stephen23
Stephen23 2020 年 10 月 15 日
Tim Johansson
Tim Johansson 2020 年 10 月 16 日
Thanks, it worked.

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

回答 (1 件)

Sudhakar Shinde
Sudhakar Shinde 2020 年 10 月 15 日
編集済み: Sudhakar Shinde 2020 年 10 月 15 日
You can use 'int2str'
for i=1:400
run_i=['C:\Users\unknown\run_',int2str(i)];
end
%or
for i=1:400
run_i=strcat('C:\Users\unknown\run_',num2str(i));
end
  2 件のコメント
Stephen23
Stephen23 2020 年 10 月 15 日
Or use the recommended and more versatile sprintf.
Tim Johansson
Tim Johansson 2020 年 10 月 16 日
Thanks for the help

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by