Calculate min/max/mean value every 100 points
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hey! I have an array with 17 999 elements and for every 100 points I want to calculate min, max and mean values. First I thought about using reshape and convert the array into a table with 100 rows and just calculate what I need for every column but it doesn't work with the number of elelmts that I have. I am wondering if there is any other way?
1 commentaire
Image Analyst
le 15 Fév 2022
Does your window of 100 elements slide along one element at a time (see movmean, etc), or does it move in "jumps" of 100 elements? What are your plans for the last 99 points? Why is your vector not a multiple of 100?
Réponses (3)
Rik
le 15 Fév 2022
Reshape will work, but you have to pad with NaN values and set the 'omitnan' flag:
data=rand(1,17999);
data(end+(1:mod(-end,100)))=NaN;
data=reshape(data,100,[]);
mean(data,'omitnan')
0 commentaires
David Hill
le 15 Fév 2022
Just remove the last 99 elements. If you need the mean, max, min for the last 99 elements, calculate them separately.
r=reshape(yourMatrix(1:17900),100,[]);
Min=min(r);
Max=max(r);
Mean=mean(r);
0 commentaires
William Rose
le 15 Fév 2022
N=17999;
M=1000;
P=floor(N/M);
x=rand(1,N);
xavg=zeros(1,P); %allocate array for average values
for i=1:P
xavg(i)=mean(x((i-1)*M+1:i*M));
end
plot(1:P,xavg,'-r*')
Try it. Good luck.
1 commentaire
William Rose
le 15 Fév 2022
@Liliya Vasilevich, Now I see that you requested every 100 points, and I wrote a script for 1000 points. Change M from 1000 to 100 to get the average every 100 points.
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
