For loop to iterate through variable

3 ビュー (過去 30 日間)
Aakash Soni
Aakash Soni 2021 年 5 月 20 日
コメント済み: Aakash Soni 2021 年 5 月 20 日
I have a following piece of code and need to convert it using for loop.
[lnCorrectSub2Vid1] = lineCorrection(bScrnSub2_vid1.ecg, vid1{1,2}.ecg);
[lnCorrectSub2Vid2] = lineCorrection(bScrnSub2_vid2.ecg, vid2{1,2}.ecg);
[lnCorrectSub2Vid3] = lineCorrection(bScrnSub2_vid3.ecg, vid3{1,2}.ecg);
[lnCorrectSub2Vid4] = lineCorrection(bScrnSub2_vid4.ecg, vid4{1,2}.ecg);
[lnCorrectSub2Vid5] = lineCorrection(bScrnSub2_vid5.ecg, vid5{1,2}.ecg);
[lnCorrectSub2Vid6] = lineCorrection(bScrnSub2_vid6.ecg, vid6{1,2}.ecg);
[lnCorrectSub2Vid7] = lineCorrection(bScrnSub2_vid7.ecg, vid7{1,2}.ecg);
[lnCorrectSub2Vid8] = lineCorrection(bScrnSub2_vid8.ecg, vid8{1,2}.ecg);
I wrote following code using for loop (I want do something like this) but I do not know how to iterate through variable.
for jj = 1:8
bslnCorrectSub2Vid(jj) = baselineCorrection(bScrnSub2_vid(jj).ecg, vid(jj){1,2}.ecg);
end
Can I iterate through variable or should I change variable naming?

採用された回答

Rik
Rik 2021 年 5 月 20 日
You painted yourself in a corner by storing data in a variable name.
If you had used a cell array from the start, you could have used easy indexing.
The solution is to change how your data is created. Make sure not to rely on a variable name. Your entire code should still make sense if you rename a variable.
  1 件のコメント
Aakash Soni
Aakash Soni 2021 年 5 月 20 日
Hi @Rik, Thank you for your answer. I am using cell array now. It is solved now.

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

その他の回答 (0 件)

カテゴリ

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