Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

How would I locate non-zeros given a condition?

1 vue (au cours des 30 derniers jours)
Aadi Duggal
Aadi Duggal le 28 Jan 2020
Clôturé : MATLAB Answer Bot le 20 Août 2021
Say that I have the matrix
1 0 1 1
0 0 0 1
0 0 0 0
and I want to find the row with a non-zero in the 4th column and at least 1 more non-zero in columns 1-3. Anyone know how I would approach this?
  2 commentaires
Walter Roberson
Walter Roberson le 29 Jan 2020
This looks like homework.
Aadi Duggal
Aadi Duggal le 29 Jan 2020
Haha, the original question was about lottery numbers on an excel file that had the same value as the 6th number and values 1-5. I tried setting up a logic statement to get 1s and 0s but wasn’t sure how to use “find” with the condition. Our professor told us to “use google and your resources” before asking them, so I’m just taking that to heart.

Réponses (1)

Alex Mcaulley
Alex Mcaulley le 28 Jan 2020
For example:
A = [1 0 1 1
0 0 0 1
0 0 0 0];
rows = find(A(:,4) & sum(A(:,1:3)~=0,2));
  1 commentaire
Aadi Duggal
Aadi Duggal le 28 Jan 2020
Thanks a lot, really appreciate it

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by