Finding the nonzero element in a specific row

4 visualizzazioni (ultimi 30 giorni)
Mohammad Mahmoud
Mohammad Mahmoud il 18 Lug 2019
Commentato: infinity il 18 Lug 2019
If i have a matrix and i want to find the indices of a non zero elements in a specific row only how can i do that ?

Risposte (2)

infinity
infinity il 18 Lug 2019
Modificato: infinity il 18 Lug 2019
Hello,
Yes, there is. You can refer this simple example
A = [1 2; 0 3]
[rows,cols,vals] = find(A==0)
  2 Commenti
Mohammad Mahmoud
Mohammad Mahmoud il 18 Lug 2019
Thank you is there a simple way to make it such that
i determine which row to find
for example in your example
i want to type the row number and it gives me the index(2,2) for the non zero element
hope this clears things up
infinity
infinity il 18 Lug 2019
Hello,
You could see the answer below of @Star

Accedi per commentare.


Star Strider
Star Strider il 18 Lug 2019
Select the row, then use find:
A = [1 3 0; 2 0 4; 0 7 9]
DesiredRow = 2
cix = find(A(DesiredRow,:) ~= 0)
so:
A =
1 3 0
2 0 4
0 7 9
DesiredRow =
2
cix =
1 3

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by