Opening different folder in matlab using loop

2 ビュー (過去 30 日間)
Raj Arora
Raj Arora 2023 年 3 月 14 日
コメント済み: Raj Arora 2023 年 3 月 14 日
I have 3 different folder with name OUTPUT_DECK_1, OUTPUT_DECK_1.5, OUTPUT_DECK_2. I am saving 1, 1.5, 2 as one variable and running a loop for opening that folder but for case 1.5 it is taking value as 1.5E+0000 (some decimal value). I have attahced the code also. Can someone please suggest me the correct way to do so. So that I can take all 3 value as it is 1 1.5 and 2
Thanks in advance
vel = [1 1.5 2];
for check = 1:3
D1 = "D:\RESULTS\PRISTINE FRESH\OUTPUT_";
D = sprintf('%sDECK_%d',D1,vel(1,check))
end

採用された回答

Jan
Jan 2023 年 3 月 14 日
編集済み: Jan 2023 年 3 月 14 日
The %g instead of %d format does what you want:
vel = [1 1.5 2];
D1 = "D:\RESULTS\PRISTINE FRESH\OUTPUT_";
for check = 1:3
D = sprintf('%sDECK_%g', D1, vel(1,check))
end
Safer in the genereal case:
vel = {'1', '1.5', '2'};
D1 = "D:\RESULTS\PRISTINE FRESH\OUTPUT_";
for check = 1:3
D = sprintf('%sDECK_%s', D1, vel{check})
end
  1 件のコメント
Raj Arora
Raj Arora 2023 年 3 月 14 日
Thanks Jan.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by