Averaging the selected vector ranges
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Lev Mihailov
am 6 Nov. 2020
Kommentiert: Mathieu NOE
am 9 Nov. 2020
Hello! I need to average the values of a vector over 25 values
fr = mean(reshape(VectorTime, 25, [])); %
Error using reshape
Product of known dimensions, 25, not divisible into total number of elements, 523.
Error in TimeAndWordNN (line 1234)
frr = mean(reshape(VectorTime, 25, []));
When I try to make such a variant, I get an error, please help
for i=1:25:length(VectorTime) && i<length(VectorTime)
frr=mean(VectorTime(i:i+1)) % i(1)=1 i(2)=26
end
% tried what i need to do through the loop but nothing worked
0 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 6 Nov. 2020
hello
my 2 fold suggestion , first is new code according to your expected results , and second is based on sliding averaging - function is in attachement !
enjoy
samples = 1000;
VectorTime = 1 + sin(2*pi*(1:samples)/samples)+ 0.25*rand(1,samples);
buffer = 25; % nb of samples for averaging
% zero overlap mean averaging
for ci=1:floor(length(VectorTime)/ buffer)
start_index = 1+(ci-1)*buffer;
stop_index = min(start_index+ buffer,length(VectorTime));
time_index(ci) = round((start_index+stop_index)/2);
frr(ci) =mean(VectorTime(start_index:stop_index)) %
end
figure(1),
plot((1:samples),VectorTime,'b',time_index,frr,'or');
% sliding avg method
out = myslidingavg(VectorTime, buffer);
figure(2),
plot((1:samples),VectorTime,'b',(1:samples),out,'r');
1 Kommentar
Mathieu NOE
am 9 Nov. 2020
hello
please use this version of slidingavg (if you are interested in)
I have found a bug in the previous release
all the best
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!