|
|
Matlab logical operators
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: Bitwise operations on .Net enumerators - comp.soft-sys.matlab ...Matlab logical operators - comp.soft-sys.matlab COMPGROUPS.NET | Search ... Bitwise operations on .Net enumerators - comp.soft-sys.matlab ... Bitwise operations on .Net ... MATLAB matrix help - comp.soft-sys.matlab> > A=100*rand(10); > A=fix(A) > x=find(30<=A<=50) use the logical operator ... matlab Matlab Help with finding x and y values - comp.soft-sys.matlab ... convert logical ... Large Matrix - Replacing NaN with zeros - comp.soft-sys.matlab ...... be slightly faster (in theory) as it would not have to do the extra logical operator. ... Large Matrix - Replacing NaN with zeros - comp.soft-sys.matlab ... Does anyone ... steps to convert RGB (colored image) to binary? - comp.soft-sys ...Just using the logical operator on the whole image will convert everything below to ... Car detection with optical flow in MATLAB - comp.soft-sys.matlab ... steps to ... if A&&B else optimization and profile question - comp.soft-sys ...If I'm not mistaken, MATLAB implements the && operator as a shortcut logical operation. That is, if the left operand is false, the right one is never evaluated. between-and operator - comp.soft-sys.sas... 50. > > A=100*rand(10); > A=fix(A) > x=find(30<=A<=50) use the logical operator ... if statement not recognized - comp.soft-sys.matlab between-and operator - comp.soft-sys.sas ... Tessellation of irregular shapes - comp.soft-sys.matlab% From the FAQ: Create a logical image of a circle with specified % diameter ... fill an irregular shape with circles. > > | > > Error: Unexpected MATLAB operator ... Find a string in a cell array - comp.soft-sys.matlab... that TF = strcmp('str', C) But it gives the logical ... to Find a String Cell Array in MATLAB | eHow.com MATLAB ... out the content in a cell before performing any operations ... Remove structure - comp.soft-sys.matlab... CSSM) FAQ: >> http://matlabwiki.mathworks.com/MATLAB_FAQ >> > Thanks for the quick and logical answer. ... structure removal costs in the Gulf of Mexico for operations ... Question about bwmorph(BW,'dilate',n) and imdilate(BW,SE) - comp ...Note that BW is a logical matrix throughout my program ... Toolbox that start with "bw" refer to operations on BINARY ... details on bwmorph+skel method - MATLAB - Mofeel Groups ... Elementwise logical operations on arrays - MATLABThis MATLAB function represents a logical AND operation between values, arrays, or expressions expr1 and expr2. Operators :: Program Components (MATLABĀ®)Arithmetic, relational, and logical operators ... Arithmetic Operators. Arithmetic operators perform numeric computations, for example, adding two numbers or raising ... 7/10/2012 3:58:07 PM
|
|
|
|
|
|
|
|
|