Save variable in a for loop

3 views (last 30 days)
Miguel Albuquerque
Miguel Albuquerque on 11 Jul 2022
Hey guys, I have this code that correlates two signals with a large amount of samples, each one has 30 million. I want to save the max value of the correlation in a matrix or array, so that in the end of the cycle I can plot all the values and see the evolution of the max correlation.
I want to correlate all the surveillance_signal(30 million) with a small amount of samples of reference_signal(1000). Basically I will correlate these two signal thousand by thousand, spaced by thousand samples, till I reach the end of reference_signal.This means, first iteration:surveillance_signal(30 million) and reference_signal(1:1000), save the max correlation in a array. Second iteration surveillance_signal(30 million) and reference_signal(2000:3000), save the max correlation value.
I have this code, that does what I want, I think, but how can I save the maximum value(xMax3,yMax3) in each iteration so that in the end I can see the evolution in a plot.
reference_reshaped = reshape(Reference_signal, 1000, 4, []);
sz = size(reference_reshaped);
Surveillance_signal_samples=Surveillance_signal;
for i = 1:sz(3)
r = reference_reshaped(:,1,i);
[afmag3,doppler3] = ambgfun(r,Surveillance_signal_samples,Fs,[250000 250000],'Cut','Delay');
afmag3(afmag3>1 )= 1;
[pks3,index3] = max(afmag3);
xMax3 = doppler3(index3);
yMax3 = pks3;
textString3 = sprintf('(%.2e, %f)', xMax3, yMax3);
end
  1 Comment
Miguel Albuquerque
Miguel Albuquerque on 12 Jul 2022
Hey guys, I have done this, correlating 100000 samples with 1000 samples, is this correct?
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

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!