How to store all FOR loop iteration in a vector and plot every iteration?

3 次查看(过去 30 天)
I want to save the data of every iteration in a vector, and plot it later . Could anyone give me a hint on how to do this ?
for a=1:114
power=pote(a,:);
mean_power_50=filter(ones(1,50)/50,1,power);
power_fading=power-mean_power_50;
x1=power_fading(1:1000);
x2=power_fading(1001:2001);
x3=power_fading(2002:3002);
x4=power_fading(3003:4003);
x5=power_fading(4004:5000);
end

采纳的回答

Guillaume
Guillaume 2016-10-11
The loop is not needed at all, filter can operate on the column of whole matrices at once. However, since you're working on rows, you'll have to transpose your matrix (and transpose the result):
mean_power_50 = filter(ones(1,50)/50,1, pote.').'; %work on the whole array
power_fading = pote - mean_power_50;
You can then split it into subarrays. However do not use numbered variables. Instead put these subarrays altogether into a cell array or other container:
%assuming that power_fading is 5000 columns:
x = mat2cell(power_fading, size(power_fading, 1), [1000 1001 1001 1001 997]); %any reason why it's not 1000 for each submatrix?
  9 个评论
yusra Ch
yusra Ch 2016-10-13
Thank you so much Guillaume. The simulation still running but this errors are appearing :
Error using ifft Out of memory. Type HELP MEMORY for your options.
Error in xcorr>autocorr (line 198) c1 = real(ifft(C,[],1));
Error in xcorr (line 126) c1 = autocorr(x,maxlag);
Error in LOS_matrice (line 18) toplot = xcorr(power_split{idx}, 'coeff');
Guillaume
Guillaume 2016-10-13
The error tells you that it's running out memory when computing the inverse fourier transform during your cross correlation. This would be caused by the matrix passed to xcorr having too many columns, which may be due to a mistake I made.
If your signals are arranged by rows, then the matrix needs to be transposed before passing it to xcorr, so if you change the toplot line to:
toplot = xcorr(power_split{idx}.', 'coeff');
does it work better?
Unfortunately, I don't have the signal processing toolbox nor matlab coder so I can't really test the answer I gave you.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by