How to store all FOR loop iteration in a vector and plot every iteration?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
yusra Ch
am 11 Okt. 2016
Kommentiert: Guillaume
am 13 Okt. 2016
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
0 Kommentare
Akzeptierte Antwort
Guillaume
am 11 Okt. 2016
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 Kommentare
Guillaume
am 13 Okt. 2016
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.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!