Calculate min/max/mean value every 100 points

21 vues (au cours des 30 derniers jours)
Liliya Vasilevich
Liliya Vasilevich le 15 Fév 2022
Commenté : Image Analyst le 15 Fév 2022
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
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?

Connectez-vous pour commenter.

Réponses (3)

Rik
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')
ans = 1×180
0.5982 0.4930 0.4950 0.5386 0.4964 0.5032 0.5025 0.4941 0.5585 0.5125 0.4598 0.5637 0.4945 0.5666 0.5186 0.5374 0.4860 0.4730 0.5227 0.4853 0.5401 0.4786 0.5643 0.4976 0.4568 0.4634 0.4806 0.5300 0.4638 0.4862

David Hill
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);

William Rose
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
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.

Connectez-vous pour commenter.

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!

Translated by