Let's say that I have a random matrix:
A=ceil(randn(10,1));
and I want to find -1 and 2 values in the matrix. Which is done by following command
a=find(A==-1);
b=find(A==2);
However I' d like to use single command which in this case is:
c=find(A==-1 & A==2);
But I got empty matrix.Where is the cache.
Thanks.
>Let's say that I have a random matrix:
>A=ceil(randn(10,1));
>and I want to find -1 and 2 values in the matrix. Which is done by following command
>a=find(A==-1);
>b=find(A==2);
>However I' d like to use single command which in this case is:
>c=find(A==-1 & A==2);
>But I got empty matrix.Where is the cache.
The catch? You need OR, not AND, so you need | rather than &
"Branko" <branko_b@hotmail.com> wrote in message <gjt08k$mt1$1@fred.mathworks.com>...
> Let's say that I have a random matrix:
> A=ceil(randn(10,1));
> and I want to find -1 and 2 values in the matrix. Which is done by following command
> a=find(A==-1);
> b=find(A==2);
> However I' d like to use single command which in this case is:
> c=find(A==-1 & A==2);
> But I got empty matrix.Where is the cache.
> Thanks.
That's because a number cannot be both -1 AND 2. Are you perhaps looking for either -1 OR 2?
"Branko"
> A=ceil(randn(10,1));
> and I want to find -1 and 2 values in the matrix. Which is done by following command
> c=find(A==-1 & A==2);
> But I got empty matrix.Where is the cache...
one of the solutions
m=ceil(randn(10,1));
r=find(m==-1 | m==2)
% r = 4 9 % <- based on random data...
In article <gjt08k$mt1$1@fred.mathworks.com>, branko_b@hotmail.com
says...
> Let's say that I have a random matrix:
> A=ceil(randn(10,1));
> and I want to find -1 and 2 values in the matrix. Which is done by following command
> a=find(A==-1);
> b=find(A==2);
> However I' d like to use single command which in this case is:
> c=find(A==-1 & A==2);
> But I got empty matrix.Where is the cache.
> Thanks.
>
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Terms prior to use.