Extracting and sorting data in a column
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi For example I have a 19 x1 colunmn called Mx and I need to find the maximum value in every 2 rows till the end of the column.
Mx
20
22
23
21
34
54
23
14
67
56
34
32
21
12
43
23
56
34
32
2 Kommentare
Antworten (2)
madhan ravi
am 8 Aug. 2019
Bearbeitet: madhan ravi
am 8 Aug. 2019
Works for odd as well as even number of elements:
NewMx = max(reshape([Mx(:);...
-Inf(mod(numel(Mx),2))],2,[])) % thank you Guillaume
7 Kommentare
Jos (10584)
am 8 Aug. 2019
This works for both an even or an odd number of elements:
N = 11 ; % odd
Mx = randi(10, N, 1)
M2 = accumarray(ceil((1:numel(Mx))/2).', Mx, [], @max)
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!