Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Problematic iterative for-loop

1 Ansicht (letzte 30 Tage)
Ejay Nsugbe
Ejay Nsugbe am 12 Jul. 2019
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hi guys,
I'm trying to write a for loop to save the output of my code in rows 1-3.
This doesn't seem to be working as the loop is basically dumping the very same value into all 3 rows.
I'd be grateful if anyone can provide some insight on this.
for i = 1:3;
m(i,3) = jZC(X1,thres);
m(i,3) = jZC(X2,thres);
m(i,3) = jZC(X3,thres);
end
  4 Kommentare
Bjorn Gustavsson
Bjorn Gustavsson am 12 Jul. 2019
Well for all 3 values of i you use exactly the same right-hand-sides in the three assignments. Therefore you will get identical assignments. Further you instantly overwrite the values of m(i,3) not once but twice. Perhaps you intend your code to be something like this:
for i = 1:3;
m(i,1) = jZC(X1,thres);
m(i,2) = jZC(X2,thres);
m(i,3) = jZC(X3,thres);
end
That way you at least assign to three different components of m, but you certainly need to have changing input to the right-hand sides for the looping to be necessary and sensible...
Ejay Nsugbe
Ejay Nsugbe am 16 Jul. 2019
Thanks guys!

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by