Incrementing file names to run loop commands

9 ビュー (過去 30 日間)
John Carroll
John Carroll 2021 年 8 月 9 日
コメント済み: John Carroll 2021 年 8 月 10 日
Hello
I am trying to write a short script to input some data from a list of files. The file names have a form as followed
Sample_run1_0V_dev.s2p
Sample_run1_5V_dev.s2p
Sample_run1_10V_dev.s2p
and so on
I would like to write a script in a loop format kind of like this
for n=0:5:200
Sample_run1_[n]V = sparameters('Sample_run1_[n]V_dev.s2p')
end
I would like the loop to increment the name of the file by changing just the characters in the brackets which will always be number and they will increment by 5 with each file name.
Currently I am doing this with a command for each file. After I import I then have to process the data which I again do but creating a block that executes the process for each file name but I would like to do this with a loop so I could write the commands once then repeat it by incrementing through the file names.
Thank you for the help

採用された回答

Rik
Rik 2021 年 8 月 9 日
Use sprintf to create your variable names, use arrays to store your data. Don't use numbered variables.
  3 件のコメント
Stephen23
Stephen23 2021 年 8 月 10 日
V = 0:5:200;
N = numel(V);
C = cell(1,N);
for k = 1:N
F = sprintf('Sample_run1_%dV_dev.s2p',V(k));
C{k} = sparameters(F);
end
John Carroll
John Carroll 2021 年 8 月 10 日
This is making a little more sense to me. I'll give this a try. Thanks

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by