MATLAB: How can i find a special row

matrix row

How can i find a row which including only -1. In that A matrix how can i write a code
A=[-1,-1,0,0,0;0,0,0,-1,0;0,1,-1,0,-1;0,0,1,0,0;1,0,0,1,1]

Best Answer

You could try
blnA = logical( A == -1 );
blnOut = find( sum( blnA' ) == 1 );
variable 'blnA' finds the elements of matrix A, which are equal to -1.
The output of blnA is
blnA =
1 1 0 0 0
0 0 0 1 0
0 0 1 0 1
0 0 0 0 0
0 1 0 0 0
if there is just one '-1', the summary for each row of logical matrix blnA will be '1'.
And because the command 'sum' sums the elements of column.
So need to do a transpose.
The output of blnOut
blnOut =
2
A ha, row 2. Got it.