variable is not saving in a for loop

12 views (last 30 days)
Hey guys, I want to save xMax3 and yMax3 in two different matrixes, and it has values in each iteration, however with my code, it only saves values different from zero in the first and last iteration, where is the error. Thanks in advance
counter=1;
surveillance_reshaped = reshape(Surveillance_signal, 100000, 2, []);
reference_reshaped = reshape(Reference_signal, 1000, 2, []);
sz = size(surveillance_reshaped);
for i = 1:sz(3)
r = reference_reshaped(:,1,i);
s = surveillance_reshaped(:,1,i);
[afmag3,doppler3] = ambgfun(r,s,Fs,[250000 250000],'Cut','Delay');
afmag3(afmag3>1 )= 1;
[pks3,index3] = max(afmag3);
xMax3 = doppler3(index3);
yMax3 = pks3;
yMax3(:,i)=yMax3;
xMax3(:,i)=xMax3;
counter=counter+1
end

Accepted Answer

dpb
dpb on 12 Jul 2022
"... where is the error. (?)"
...
xMax3 = doppler3(index3);
yMax3 = pks3;
...
overwrites/redefines the two variables in their entirety each pass through the loop, thus eliminating the previous value. MATLAB assignment without subscripting means "the whole thing".
  7 Comments
Miguel Albuquerque
Miguel Albuquerque on 12 Jul 2022
Thanks a lot dpb, I have this gigantic task to do, and this little help, is so much valuable.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by