Max and Min for every change of integer?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
David Runosson
am 14 Apr. 2021
Kommentiert: Matt J
am 14 Apr. 2021
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)
0 Kommentare
Akzeptierte Antwort
Matt J
am 14 Apr. 2021
Bearbeitet: Matt J
am 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)
2 Kommentare
Matt J
am 14 Apr. 2021
You're quite welcome, but pleas Acept-click the answer to indicate that it resolved your question.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!