Max and Min for every change of integer?

1 view (last 30 days)
So i am trying to find the max and min of every subset of data in a fairly large matrix. The maxtrix will have measured values from every row from the second column to the last column. In the first column, it will have an integer that groups the data into separate orders. I would like to find the max in every order. The number of rows per order might differs, and there might also be missing values.
A simplfied dataset would be:
Order Box1 Box2
1 8 0
1 10 0
1 12 0
2 10 8
2 11 10
2 0 12
3 0 50
3 0 40
3 0 20
4 10 1
4 11 NaN
4 13 NaN
4 2 3
The output I wish to have is:
Order Max Min
1 12 0
2 12 0
3 50 0
4 13 1
The actual matrix will be failry big, in the area of 600x5000 (COLxROW)

Accepted Answer

Matt J
Matt J on 14 Apr 2021
Edited: Matt J on 14 Apr 2021
Using your example,
data=[1 8 0
1 10 0
1 12 0
2 10 8
2 11 10
2 0 12
3 0 50
3 0 40
3 0 20
4 10 1
4 11 NaN
4 13 NaN
4 2 3];
Max = splitapply(@(z)max(z,[],'all'), data(:,2:end), data(:,1));
Min = splitapply(@(z)min(z,[],'all'), data(:,2:end), data(:,1));
Order=(1:numel(Max)).';
result=table(Order,Max,Min)
result = 4×3 table
Order Max Min _____ ___ ___ 1 12 0 2 12 0 3 50 0 4 13 1
  2 Comments
Matt J
Matt J on 14 Apr 2021
You're quite welcome, but pleas Acept-click the answer to indicate that it resolved your question.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!