Info

This question is closed. Reopen it to edit or answer.

Find the highest possible value in a matrix that complies to a certain range

1 view (last 30 days)
Hello, I couldn't find a way to word my question better since English is not my native language.
For example I have this matrix A = [1 2 3; 2 2 4; 3 2 5; 4 2 6]
I want to display the elements of the lowest row in which the value of third element is < 7
So in this example, the values would be 4 and 2 and because they are the lowest row and 6 is still smaller than 7.

Answers (1)

Domanic
Domanic on 26 Jan 2018
I think I understand your question. You are interested in the row which is closest to the bottom of the matrix ('lowest' in that sense). These are actually rows with the highest index. A one line solution is:
A(find(A(:,3)<7,1,'last'),1:2)
This finds the row index of the last element of the third column of matrix, A, which has a value less than 7. Then, it displays the first two columns of the row with that index. Hope that helps.

Community Treasure Hunt

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

Start Hunting!