Azzera filtri
Azzera filtri

Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

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

2 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Domanic
Domanic il 26 Gen 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.

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by