how to select certain elements from a matrix?

A=[1,2,3,4], B=[90,0,40,0;0,0,10,60;55,15,0,10;0,15,5,0]
Hi everyone.. I want to select indexes of only one zero from each row and respective column. please help me in writing matlab code for this problem. Thanks in Advance

 채택된 답변

David Sanchez
David Sanchez 2014년 6월 11일

0 개 추천

B=[90,0,40,0;
0,0,10,60;
55,15,0,10;
0,15,5,0];
[col row]=find(B==0);
A= [row col] % coordinates of your zero-elements
A =
1 2
1 4
2 1
2 2
3 3
4 1
4 4

댓글 수: 3

In you just want the coordinates of the first zero in each row:
B=[90,0,40,0;
0,0,10,60;
55,15,0,10;
0,15,5,0];
First_zero_coordinates = zeros(size(B,1),2);
for k=1:size(B,1)
col = find(B(k,:)==0,1);
First_zero_coordinates(k,:) = [ k col];
end
First_zero_coordinates =
1 2
2 1
3 3
4 1
Uet
Uet 2014년 6월 11일
Thank you very much sir, is there any way so that i can delete repeated rows as you mentioned in A? as you can see there are double entries from 1st, 2nd and 4th rows. I want to select one from each
Uet
Uet 2014년 6월 11일
Thanks alot Sir.. Much obliged

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

질문:

Uet
2014년 6월 11일

댓글:

Uet
2014년 6월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by