Matlab logical operators

  • Follow


Z = [1 2 5 7 8 3 0 4]
How can I obtain Z1 = [1 2 0 0 0 3 0 4] from Z using the Matlab logical operators?
0
Reply Mario 3/13/2010 9:59:10 AM

"Mario Fatafehi" <coruba9@hotmail.com> wrote in message <hnfnld$7rn$1@fred.mathworks.com>...
> Z = [1 2 5 7 8 3 0 4]
> How can I obtain Z1 = [1 2 0 0 0 3 0 4] from Z using the Matlab logical operators?

I can use this to get the same answer Z1 = Z - [ 0 0 5 7 8 0 0 0] but I am not sure whether that is the right way or not? Any help?
0
Reply Mario 3/13/2010 10:19:06 AM


"Mario Fatafehi" <coruba9@hotmail.com> wrote in message <hnfnld$7rn$1@fred.mathworks.com>...
> Z = [1 2 5 7 8 3 0 4]
> How can I obtain Z1 = [1 2 0 0 0 3 0 4] from Z using the Matlab logical operators?

index = Z<5;

Z1 = Z(index);
0
Reply numandina (373) 3/13/2010 12:01:08 PM

I guess Mario is looking for this:

Z(Z<5) = 0;

Best.




<hnfuq3$1kk$1@fred.mathworks.com>...
> "Mario Fatafehi" <coruba9@hotmail.com> wrote in message <hnfnld$7rn$1@fred.mathworks.com>...
> > Z = [1 2 5 7 8 3 0 4]
> > How can I obtain Z1 = [1 2 0 0 0 3 0 4] from Z using the Matlab logical operators?
> 
> index = Z<5;
> 
> Z1 = Z(index);
0
Reply sadik.hava (254) 3/13/2010 12:21:02 PM

"Husam Aldahiyat" <numandina@gmail.com> wrote in message <hnfuq3$1kk$1@fred.mathworks.com>...
> "Mario Fatafehi" <coruba9@hotmail.com> wrote in message <hnfnld$7rn$1@fred.mathworks.com>...
> > Z = [1 2 5 7 8 3 0 4]
> > How can I obtain Z1 = [1 2 0 0 0 3 0 4] from Z using the Matlab logical operators?
> 
> index = Z<5;
> 
> Z1 = Z(index);

This gives >> index = Z<5

index =

     1     1     0     0     0     1     1     1

>> Z1 = Z(index) 

Z1 =

     1     2     3     0     4
but not the 1 2 0 0 0 3 0 4
0
Reply coruba9 (12) 3/13/2010 12:21:02 PM

"Sadik " <sadik.hava@gmail.com> wrote in message <hnfvve$j9k$1@fred.mathworks.com>...
> I guess Mario is looking for this:
> 
> Z(Z<5) = 0;
> 
> Best.

It is not right and I am trying to manipulate to get it right.
 Z(Z<5) = 0

Z =   0     0     5     7     8     0     0     0
> 
> 
> 
> 
> <hnfuq3$1kk$1@fred.mathworks.com>...
> > "Mario Fatafehi" <coruba9@hotmail.com> wrote in message <hnfnld$7rn$1@fred.mathworks.com>...
> > > Z = [1 2 5 7 8 3 0 4]
> > > How can I obtain Z1 = [1 2 0 0 0 3 0 4] from Z using the Matlab logical operators?
> > 
> > index = Z<5;
> > 
> > Z1 = Z(index);
0
Reply coruba9 (12) 3/13/2010 12:50:21 PM

"Mario Fatafehi" <coruba9@hotmail.com> wrote in message <hng1md$jjm$1@fred.mathworks.com>...
> "Sadik " <sadik.hava@gmail.com> wrote in message <hnfvve$j9k$1@fred.mathworks.com>...
> > I guess Mario is looking for this:
> > 
> > Z(Z<5) = 0;
> > 
> > Best.
> 
> It is not right and I am trying to manipulate to get it right.
>  Z(Z<5) = 0
> 
> Z =   0     0     5     7     8     0     0     0
> > 
> > 
> > 
> > 
> > <hnfuq3$1kk$1@fred.mathworks.com>...
> > > "Mario Fatafehi" <coruba9@hotmail.com> wrote in message <hnfnld$7rn$1@fred.mathworks.com>...
> > > > Z = [1 2 5 7 8 3 0 4]
> > > > How can I obtain Z1 = [1 2 0 0 0 3 0 4] from Z using the Matlab logical operators?
> > > 
> > > index = Z<5;
> > > 
> > > Z1 = Z(index);

Hi Mario, one way

Z = [1 2 5 7 8 3 0 4];
Indices = find(Z<5);
Z1 = double(Z<5);
Z1(Indices)=Z(Indices);

Wayne
0
Reply wmkingty (1429) 3/13/2010 1:40:21 PM

I am sorry. I got it the other way around. This should work:

Z(Z>4) = 0;

Best.


"Mario Fatafehi" <coruba9@hotmail.com> wrote in message <hng1md$jjm$1@fred.mathworks.com>...
> "Sadik " <sadik.hava@gmail.com> wrote in message <hnfvve$j9k$1@fred.mathworks.com>...
> > I guess Mario is looking for this:
> > 
> > Z(Z<5) = 0;
> > 
> > Best.
> 
> It is not right and I am trying to manipulate to get it right.
>  Z(Z<5) = 0
> 
> Z =   0     0     5     7     8     0     0     0
> > 
> > 
> > 
> > 
> > <hnfuq3$1kk$1@fred.mathworks.com>...
> > > "Mario Fatafehi" <coruba9@hotmail.com> wrote in message <hnfnld$7rn$1@fred.mathworks.com>...
> > > > Z = [1 2 5 7 8 3 0 4]
> > > > How can I obtain Z1 = [1 2 0 0 0 3 0 4] from Z using the Matlab logical operators?
> > > 
> > > index = Z<5;
> > > 
> > > Z1 = Z(index);
0
Reply sadik.hava (254) 3/13/2010 5:12:05 PM

"Mario Fatafehi" <coruba9@hotmail.com> wrote in message <hnfnld$7rn$1@fred.mathworks.com>...
> Z = [1 2 5 7 8 3 0 4]
> How can I obtain Z1 = [1 2 0 0 0 3 0 4] from Z using the Matlab logical operators?

Here is an one-liner:

Z = [1 2 5 7 8 3 0 4] ; 

Z1 = Z .* (Z<5)


Jos
0
Reply 10584 (922) 3/14/2010 6:10:05 PM

Mario Fatafehi wrote:
> "Sadik " <sadik.hava@gmail.com> wrote in message 
> <hnfvve$j9k$1@fred.mathworks.com>...
>> I guess Mario is looking for this:
>>
>> Z(Z<5) = 0;
>>
>> Best.
> 
> It is not right and I am trying to manipulate to get it right.
> Z(Z<5) = 0
> 
> Z =   0     0     5     7     8     0     0     0
....

Well, that manipulation would be

z(~(z>5))   % Nota Bene: that Sadik posted his intended version... :)

--
0
Reply none1568 (6639) 3/14/2010 6:31:33 PM

9 Replies
201 Views

(page loaded in 0.891 seconds)

Similiar Articles:













7/10/2012 3:58:07 PM


Reply: