how to get the output of an if statement in a matrix
Show older comments
Hello-- I have a question and it is very important to me. I will appreciate if anyone could help me on this issue! WE have two matrices: one is r(40*80) and the other one is s(8*1) Also we know that 8 rows of matrix r are zeros. ( for example : rows number 6,9,19,23,25,32,33,38 )
I need a code to just write the numbers of zero rows ( which are listed above ) in the s matrix in the order. I wrote this:
s=zeros(8,1);
for row_number = 1:40
A=r(row_number,:);
[i,v,c]=find(A);
row_number;
max(v);
min(v);
c;
if isempty(max(v))
for h=1:8
s(h,1)=row_number;
hold on
end
s
end
and this is the answer I got!
s =
6
6
6
6
6
6
6
6
s =
9
9
9
9
9
9
9
9
s =
19
19
19
19
19
19
19
19
s =
23
23
23
23
23
23
23
23
s =
25
25
25
25
25
25
25
25
s =
32
32
32
32
32
32
32
32
s =
33
33
33
33
33
33
33
33
s =
38
38
38
38
38
38
38
38
What I need to have is simply an answer with this form : s =
6
9
19
23
25
32
33
38
the reason I use find(A) was to do some calculations with min(v) and max(v) for rows with non zero elements. I will be thankful of anyone helping me with this. Best, Homayoon
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!