Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matlab logical operators

Subject: Matlab logical operators

From: Mario Fatafehi

Date: 13 Mar, 2010 09:59:10

Message: 1 of 10

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?

Subject: Matlab logical operators

From: Mario Fatafehi

Date: 13 Mar, 2010 10:19:06

Message: 2 of 10

"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?

Subject: Matlab logical operators

From: Husam Aldahiyat

Date: 13 Mar, 2010 12:01:08

Message: 3 of 10

"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);

Subject: Matlab logical operators

From: Mario Fatafehi

Date: 13 Mar, 2010 12:21:02

Message: 4 of 10

"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

Subject: Matlab logical operators

From: Sadik

Date: 13 Mar, 2010 12:21:02

Message: 5 of 10

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);

Subject: Matlab logical operators

From: Mario Fatafehi

Date: 13 Mar, 2010 12:50:21

Message: 6 of 10

"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);

Subject: Matlab logical operators

From: Wayne King

Date: 13 Mar, 2010 13:40:21

Message: 7 of 10

"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

Subject: Matlab logical operators

From: Sadik

Date: 13 Mar, 2010 17:12:05

Message: 8 of 10

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);

Subject: Matlab logical operators

From: Jos (10584)

Date: 14 Mar, 2010 18:10:05

Message: 9 of 10

"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

Subject: Matlab logical operators

From: dpb

Date: 14 Mar, 2010 18:31:33

Message: 10 of 10

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... :)

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us