Finding maximum between every two rows of a matrix

1 view (last 30 days)
Hello everyone,
I have a matrix that I am trying to break up based on maximums. I will explain this with a simplified example. So I have a matrix as follows:
A=[1 2 3;6 7 8;4 5 6;1 2 3;4 5 6;1 2 3];
I am trying to create a new matrix based off of this matrix as follows. I want to include the first and last row UN-changed in the new matrix, then find the maximum between every two rows of column 2 and return that row to the new matrix. So the new matrix would be
newA=[1 2 3;6 7 8;4 5 6;1 2 3]
So the first row in newA is [1 2 3] because it is left unchanged. Row 2 is [6 7 8] because between row 2 and 3, row 2 has the larger value in column 2. Row 3 is [4 5 6] because between row 4 and 5, row 5 has the larger value in column 2. Row 4 is [1 2 3] because it is left unchanged.
Any help would be great. Thanks!

Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!