How can I find a row in a matrix in which all elements apply to a relational operator?

1 visualización (últimos 30 días)
I have a large data set and would like to know how I could find all the rows in which each element has a certain value. The matrix could look like this:
A =
0 0 0 0 0 0 0 0
0 0 0 0.1000 0.1000 0 0 0
0 0 0.1000 0.3000 0.3000 0.1000 0 0
0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000 0.3000
0.3000 0.3000 0.3000 0.1000 0.1000 0.3000 0.3000 0.3000
0 0 0.1000 0.3000 0.3000 0.1000 0 0
How could I find the fourth row if my requirement is that every element in a row should be larger than 0.25? I already looked into functions like unique, find and all, but I could not modify them in such way that it applies to a row. Preferably I would get a column containing the number of all the rows that applies to the condition. Thanks in advance!

Respuesta aceptada

Stephen23
Stephen23 el 19 de Sept. de 2019
Editada: Stephen23 el 19 de Sept. de 2019
>> idx = all(A>0.25,2) % logical index
idx =
0
0
0
1
0
0
>> find(idx) % subscript index
ans =
4
In many cases using logical indices is more efficient than subscript indices.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by