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:
Different Linear Combinations

Subject: Different Linear Combinations

From: Lin

Date: 5 Feb, 2009 12:11:02

Message: 1 of 6

for example,

I got 2 scalar variables X and Y. 4 different combinations can be generated ( X & Y can only take the value of 0 or 1 )
 
X Y
0 0 % 1st set of value to be sub. into the following equation
0 1 % 2nd set of value
1 0 % 3rd set of value
1 1 % Last set of value

Equation: X*[1;0] + Y*[0;1]

expected results = [ 0 1 1; 1 0 1]

How can I achieve this? Thanks.

Subject: Different Linear Combinations

From: Matt

Date: 5 Feb, 2009 12:25:03

Message: 2 of 6

"Lin " <shenqlv@yahoo.com> wrote in message <gmel0m$sh1$1@fred.mathworks.com>...
> for example,
>
> I got 2 scalar variables X and Y. 4 different combinations can be generated ( X & Y can only take the value of 0 or 1 )
>
> X Y
> 0 0 % 1st set of value to be sub. into the following equation
> 0 1 % 2nd set of value
> 1 0 % 3rd set of value
> 1 1 % Last set of value
>
> Equation: X*[1;0] + Y*[0;1]
>
> expected results = [ 0 1 1; 1 0 1]
>
> How can I achieve this? Thanks.



 dec2bin(0:3)'-'0'

Good enough?

Subject: Different Linear Combinations

From: David

Date: 5 Feb, 2009 12:28:02

Message: 3 of 6

"Lin " <shenqlv@yahoo.com> wrote in message <gmel0m$sh1$1@fred.mathworks.com>...
> for example,
>
> I got 2 scalar variables X and Y. 4 different combinations can be generated ( X & Y can only take the value of 0 or 1 )
>
> X Y
> 0 0 % 1st set of value to be sub. into the following equation
> 0 1 % 2nd set of value
> 1 0 % 3rd set of value
> 1 1 % Last set of value
>
> Equation: X*[1;0] + Y*[0;1]
>
> expected results = [ 0 1 1; 1 0 1]
>
> How can I achieve this? Thanks.

too much doesn't make sense. you state you have inputs X and Y and you have an equation that uses them. but you state there are 4 possible combinations, but then have expected results that only has 3 outputs. something seems to be missing.

Subject: Different Linear Combinations

From: Lin

Date: 5 Feb, 2009 14:07:02

Message: 4 of 6

Yes. it works. With that I wrote the rest of the program and got my expected results.
Though it is not very well written, but at least it works. Cheers.

ix = dec2bin(0:3)'-'0'
x = ix(1,:);
y = ix(2,:);
 
a = 1;
z = cell (1,4);

for i = 1:4
     z{a} = x(i)*[1;0] + y(i)*[0;1];
     a = a+1;
end;

David, there is a set of value where both x and y are 0. Hence, I will only get 3 results.
Hope this will clear up your doubts.

"Matt " <xys@whatever.com> wrote in message <gmelqv$3n4$1@fred.mathworks.com>...
> "Lin " <shenqlv@yahoo.com> wrote in message <gmel0m$sh1$1@fred.mathworks.com>...
> > for example,
> >
> > I got 2 scalar variables X and Y. 4 different combinations can be generated ( X & Y can only take the value of 0 or 1 )
> >
> > X Y
> > 0 0 % 1st set of value to be sub. into the following equation
> > 0 1 % 2nd set of value
> > 1 0 % 3rd set of value
> > 1 1 % Last set of value
> >
> > Equation: X*[1;0] + Y*[0;1]
> >
> > expected results = [ 0 1 1; 1 0 1]
> >
> > How can I achieve this? Thanks.
>
>
>
> dec2bin(0:3)'-'0'
>
> Good enough?

Subject: Different Linear Combinations

From: Lin

Date: 5 Feb, 2009 15:44:02

Message: 5 of 6

I tried to expand my program so I replaced "z{a} = x(i)*[1;0] + y(i)*[0;1]" with
" z{a} = [x(i)*content(1,2) + y(i)*content(2,2)] " but got an error.

error statement < Undefined function or method 'mtimes' for input arguments of type 'cell' >

What is the error all about and how can I remove it? Thanks.

%My program

content{1,2} = [1;0];
content{2,2} = [0;1];
    
 ix = dec2bin(0:3)'-'0'
 
 x = ix(1,:);
 y = ix(2,:);
 
 a = 1;
 z = cell (1,4);

 for i = 1:4
     z{a} = [x(i)*content(1,2) + y(i)*content(2,2)];
     a = a+1;
 end;

%end of program


"Lin " <shenqlv@yahoo.com> wrote in message <gmerq6$hv4$1@fred.mathworks.com>...
> Yes. it works. With that I wrote the rest of the program and got my expected results.
> Though it is not very well written, but at least it works. Cheers.
>
> ix = dec2bin(0:3)'-'0'
> x = ix(1,:);
> y = ix(2,:);
>
> a = 1;
> z = cell (1,4);
>
> for i = 1:4
> z{a} = x(i)*[1;0] + y(i)*[0;1];
> a = a+1;
> end;
>
> David, there is a set of value where both x and y are 0. Hence, I will only get 3 results.
> Hope this will clear up your doubts.
>
> "Matt " <xys@whatever.com> wrote in message <gmelqv$3n4$1@fred.mathworks.com>...
> > "Lin " <shenqlv@yahoo.com> wrote in message <gmel0m$sh1$1@fred.mathworks.com>...
> > > for example,
> > >
> > > I got 2 scalar variables X and Y. 4 different combinations can be generated ( X & Y can only take the value of 0 or 1 )
> > >
> > > X Y
> > > 0 0 % 1st set of value to be sub. into the following equation
> > > 0 1 % 2nd set of value
> > > 1 0 % 3rd set of value
> > > 1 1 % Last set of value
> > >
> > > Equation: X*[1;0] + Y*[0;1]
> > >
> > > expected results = [ 0 1 1; 1 0 1]
> > >
> > > How can I achieve this? Thanks.
> >
> >
> >
> > dec2bin(0:3)'-'0'
> >
> > Good enough?

Subject: Different Linear Combinations

From: Matt

Date: 5 Feb, 2009 16:01:02

Message: 6 of 6

"Lin " <shenqlv@yahoo.com> wrote in message <gmf1g2$t08$1@fred.mathworks.com>...
> I tried to expand my program so I replaced "z{a} = x(i)*[1;0] + y(i)*[0;1]" with
> " z{a} = [x(i)*content(1,2) + y(i)*content(2,2)] " but got an error.
>
> error statement < Undefined function or method 'mtimes' for input arguments of type 'cell' >
>
> What is the error all about and how can I remove it? Thanks.

z{a} = [x(i)*content{1,2} + y(i)*content{2,2}]

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