Where is the mistake of this code?
Show older comments
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 Comments
madhan ravi
on 8 Apr 2019
Please explicitly show how your expected result should look like.
Alex Yande
on 8 Apr 2019
madhan ravi
on 8 Apr 2019
So according to what I understand you want to find first nonzero entry in each row in reverse order?
Alex Yande
on 8 Apr 2019
Edited: Alex Yande
on 8 Apr 2019
Alex Yande
on 8 Apr 2019
Accepted Answer
More Answers (0)
Categories
Find more on Naming Conventions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!