필터 지우기
필터 지우기

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

조회 수: 2 (최근 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개)

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by