How to find whether any non-zero row vector or column vector is there in a matrix?
1 view (last 30 days)
Show older comments
DURAI KUMAR M
on 23 Jan 2014
Answered: Roger Stafford
on 23 Jan 2014
i am not sure whether any function is there for finding this, basically i'm checking any row of a matrix A(m*n) is equal to the row vector R(1*n) for example, A=magic[5];A(3,:)=13; & R=[13,13,13]; i want to identify the presence of the R vector in A, i used bsx function fr this, comp=bsxfun(@eq,A,R); Res=any(comp); it got me a proper result, if comp(logical result)=[1,0,0;0,1,0;0,0,1] any function gives ans as [1,1,1] but all i need is if comp is something like this [1,0,0;0,1,0;1,1,1] then only it should give result as[1,1,1] which function should i use? basically if any full row of elements are ones.
any suggestion or helps are appreciated, thanks in advance. Durai.
0 Comments
Accepted Answer
Roger Stafford
on 23 Jan 2014
Do:
Res = all(comp,2);
instead of
Res=any(comp);
That will tell you which rows of A are identical to R.
0 Comments
More Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices 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!