For loop to iterate through variable

3 visualizaciones (últimos 30 días)
Aakash Soni
Aakash Soni el 20 de Mayo de 2021
Comentada: Aakash Soni el 20 de Mayo de 2021
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?

Respuesta aceptada

Rik
Rik el 20 de Mayo de 2021
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 comentario
Aakash Soni
Aakash Soni el 20 de Mayo de 2021
Hi @Rik, Thank you for your answer. I am using cell array now. It is solved now.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by