For loop to iterate through variable

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by