Find a row with all elements satisfying a condition
Ältere Kommentare anzeigen
I have a matrix that looks something like this:
mat = [20, 3; 43 0; 8 3; 100 3; 3 9];
I want to find the rows of the matrix that all of its elements are satisfying a certain condition. For example, if the condition is:
> 10
The result matrix will be:
[8 3; 3 9];
Because those are the only rows in the matrix that both of their elements are smaller then 10. Is there an easy way to achieve this result? Thanks!
Akzeptierte Antwort
Weitere Antworten (1)
darova
am 24 Jun. 2020
Use logical indexing
mat = [20, 3; 43 0; 8 3; 100 3; 3 9]
ix = sum(mat<10,2)>1;
a1 = mat(ix,:)
Kategorien
Mehr zu Mathematics and Optimization finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!