Where is the mistake of this code?
Afficher commentaires plus anciens
I have a matrix named as v_s and want to find first 1 value's location with using any reference matrix. v_s has 3 columns and locations should create a matrix named as v_d.
I have already coded this operation, but don't know where is my mistake. May you help me?
Thanks,
Note: first two statement(==0 and ==99) can be stay fixed and not be changed.
b=3;
v_d=rand(b,1);
v_s=[0 0 0 0 0 1; 0 0 0 0 0 1; 0 0 0 0 1 0]
for j=1:b;
if v_s(j,:)==0
v_d(j)=0
elseif v_s(j,:)==99
v_d(j)=99;
elseif v_s(j,:)~=0
ref=[6 5 4 3 2 1];
v_d(j)=ref(find(v_s(j,:)==1,1,'first'))
end
end
5 commentaires
madhan ravi
le 8 Avr 2019
Please explicitly show how your expected result should look like.
Alex Yande
le 8 Avr 2019
madhan ravi
le 8 Avr 2019
So according to what I understand you want to find first nonzero entry in each row in reverse order?
Alex Yande
le 8 Avr 2019
Modifié(e) : Alex Yande
le 8 Avr 2019
Alex Yande
le 8 Avr 2019
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!