Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Setting up linear multiple regression matrix

Subject: Setting up linear multiple regression matrix

From: fas

Date: 18 Jul, 2008 06:03:14

Message: 1 of 12

I have
A=[1 X; 0 X];
b=[Y;Z];
where X, Y and Z are vectors and I want to do x=A\b to find two
coefficients x1 and x2. I am finding it hard to arrange the vectors in
the matrix form for the required regression.
Any help please ?

Subject: Setting up linear multiple regression matrix

From: Greg Heath

Date: 18 Jul, 2008 09:58:14

Message: 2 of 12

On Jul 18, 2:03=A0am, fas <faisalmu...@gmail.com> wrote:
> I have
> A=3D[1 X; 0 X];

X must be a row vector

> b=3D[Y;Z];
> where X, Y and Z are vectors

It looks like you want X,Y,Z to have the same dimensions .. [ 1 n]

size(A) =3D [ 2 n+1 ]
size(b) =3D [ 2 n ]

=3D=3D> size(A\b) =3D [ n+1 n]

> and I want to do x=3DA\b to find two
> coefficients x1 and x2.

It does not compute.

>I am finding it hard to arrange the vectors in
> the matrix form for the required regression.
> Any help please ?

Begin by using less confusing notation;
e.g., X,Y,Z --> U,Y,Z

Next, explicitly state the dimensions of ALL variables U,Y,Z,A,b,x.

It looks like you are just trying to solve A*x=3Db, given A and b.

This is not a regression problem.

Hope this helps.

Greg

Subject: Setting up linear multiple regression matrix

From: fas

Date: 18 Jul, 2008 11:40:18

Message: 3 of 12

On Jul 18, 7:58 pm, Greg Heath <he...@alumni.brown.edu> wrote:
> On Jul 18, 2:03 am, fas <faisalmu...@gmail.com> wrote:
>
> > I have
> > A=[1 X; 0 X];
>
> X must be a row vector
>
> > b=[Y;Z];
> > where X, Y and Z are vectors
>
> It looks like you want X,Y,Z to have the same dimensions .. [ 1 n]
>
> size(A) = [ 2 n+1 ]
> size(b) = [ 2 n ]
>
> ==> size(A\b) = [ n+1 n]
>
> > and I want to do x=A\b to find two
> > coefficients x1 and x2.
>
> It does not compute.
>
> >I am finding it hard to arrange the vectors in
> > the matrix form for the required regression.
> > Any help please ?
>
> Begin by using less confusing notation;
> e.g., X,Y,Z --> U,Y,Z
>
> Next, explicitly state the dimensions of ALL variables U,Y,Z,A,b,x.
>
> It looks like you are just trying to solve A*x=b, given A and b.
>
> This is not a regression problem.
>
> Hope this helps.
>
> Greg
My A matrix is like that
A=
[1 X1;
 0 X1;
1 X2;
0 X2;
....
1 Xn;
0 Xn]
b=
[Y1;
Z1;
Y2;
Z2;
..
Yn;
Zn]

and finally
x=[a;b]
If I manually supply few vectors values for X,Y,Z I do get a& b.
like
x=A\b;
but my only problem is I do not want to enter the vector values may be
repmat or some other command may help me. I have tried but did not
have success :(

Subject: Setting up linear multiple regression matrix

From: Greg Heath

Date: 18 Jul, 2008 16:56:03

Message: 4 of 12

On Jul 18, 7:40=A0am, fas <faisalmu...@gmail.com> wrote:
> On Jul 18, 7:58 pm, Greg Heath <he...@alumni.brown.edu> wrote:
>
>
>
> > On Jul 18, 2:03 am, fas <faisalmu...@gmail.com> wrote:
>
> > > I have
> > > A=3D[1 X; 0 X];
>
> > X must be a row vector
>
> > > b=3D[Y;Z];
> > > where X, Y and Z are vectors
>
> > It looks like you want X,Y,Z to have the same dimensions .. [ 1 n]
>
> > size(A) =3D [ 2 =A0n+1 ]
> > size(b) =3D [ 2 =A0n ]
>
> > =3D=3D> size(A\b) =3D [ n+1 n]
>
> > > and I want to do x=3DA\b to find two
> > > coefficients x1 and x2.
>
> > It does not compute.
>
> > >I am finding it hard to arrange the vectors in
> > > the matrix form for the required regression.
> > > Any help please ?
>
> > Begin by using less confusing notation;
> > e.g., X,Y,Z --> U,Y,Z
>
> > Next, explicitly state the dimensions of ALL variables U,Y,Z,A,b,x.
>
> > It looks like you are just trying to solve A*x=3Db, given A and b.
>
> > This is not a regression problem.
>
> > Hope this helps.
>
> > Greg
>
> My A matrix is like that
> A=3D
> [1 =A0 X1;
> =A00 =A0 X1;
> 1 =A0 X2;
> 0 =A0 X2;
> ....
> 1 =A0Xn;
> 0 =A0Xn]
> b=3D
> [Y1;
> Z1;
> Y2;
> Z2;
> ..
> Yn;
> Zn]
>
> and finally
> x=3D[a;b]
> If I manually supply few vectors values for X,Y,Z I do get a& b.
> like
> x=3DA\b;
> but my only problem is I do not want to enter the vector values may be
> repmat or some other command may help me. I have tried but did not
> have success

Look up row permutation matrices and apply them to

[ ones(n,1) X ; zeros(n,1) X ]

and

[ Y; Z]

Hope this helps.

Greg

Subject: Setting up linear multiple regression matrix

From: fas

Date: 21 Jul, 2008 05:05:50

Message: 5 of 12

On Jul 19, 2:56 am, Greg Heath <he...@alumni.brown.edu> wrote:
> On Jul 18, 7:40 am, fas <faisalmu...@gmail.com> wrote:
>
>
>
> > On Jul 18, 7:58 pm, Greg Heath <he...@alumni.brown.edu> wrote:
>
> > > On Jul 18, 2:03 am, fas <faisalmu...@gmail.com> wrote:
>
> > > > I have
> > > > A=[1 X; 0 X];
>
> > > X must be a row vector
>
> > > > b=[Y;Z];
> > > > where X, Y and Z are vectors
>
> > > It looks like you want X,Y,Z to have the same dimensions .. [ 1 n]
>
> > > size(A) = [ 2 n+1 ]
> > > size(b) = [ 2 n ]
>
> > > ==> size(A\b) = [ n+1 n]
>
> > > > and I want to do x=A\b to find two
> > > > coefficients x1 and x2.
>
> > > It does not compute.
>
> > > >I am finding it hard to arrange the vectors in
> > > > the matrix form for the required regression.
> > > > Any help please ?
>
> > > Begin by using less confusing notation;
> > > e.g., X,Y,Z --> U,Y,Z
>
> > > Next, explicitly state the dimensions of ALL variables U,Y,Z,A,b,x.
>
> > > It looks like you are just trying to solve A*x=b, given A and b.
>
> > > This is not a regression problem.
>
> > > Hope this helps.
>
> > > Greg
>
> > My A matrix is like that
> > A=
> > [1 X1;
> > 0 X1;
> > 1 X2;
> > 0 X2;
> > ....
> > 1 Xn;
> > 0 Xn]
> > b=
> > [Y1;
> > Z1;
> > Y2;
> > Z2;
> > ..
> > Yn;
> > Zn]
>
> > and finally
> > x=[a;b]
> > If I manually supply few vectors values for X,Y,Z I do get a& b.
> > like
> > x=A\b;
> > but my only problem is I do not want to enter the vector values may be
> > repmat or some other command may help me. I have tried but did not
> > have success
>
> Look up row permutation matrices and apply them to
>
> [ ones(n,1) X ; zeros(n,1) X ]
>
> and
>
> [ Y; Z]
>
> Hope this helps.
>
> Greg

Hi Greg
I gave the format for my A matrix, as such its not created and I have
to create my A and b matrices. I have only given their format. Can you
help me a bit further ?

Subject: Setting up linear multiple regression matrix

From: Greg Heath

Date: 21 Jul, 2008 17:12:09

Message: 6 of 12

On Jul 21, 1:05=A0am, fas <faisalmu...@gmail.com> wrote:
> On Jul 19, 2:56 am,Greg Heath<he...@alumni.brown.edu> wrote:
>
>
>
>
>
> > On Jul 18, 7:40 am, fas <faisalmu...@gmail.com> wrote:
>
> > > On Jul 18, 7:58 pm,Greg Heath<he...@alumni.brown.edu> wrote:
>
> > > > On Jul 18, 2:03 am, fas <faisalmu...@gmail.com> wrote:
>
> > > > > I have
> > > > > A=3D[1 X; 0 X];
>
> > > > X must be a row vector
>
> > > > > b=3D[Y;Z];
> > > > > where X, Y and Z are vectors
>
> > > > It looks like you want X,Y,Z to have the same dimensions .. [ 1 n]
>
> > > > size(A) =3D [ 2 =A0n+1 ]
> > > > size(b) =3D [ 2 =A0n ]
>
> > > > =3D=3D> size(A\b) =3D [ n+1 n]
>
> > > > > and I want to do x=3DA\b to find two
> > > > > coefficients x1 and x2.
>
> > > > It does not compute.
>
> > > > >I am finding it hard to arrange the vectors in
> > > > > the matrix form for the required regression.
> > > > > Any help please ?
>
> > > > Begin by using less confusing notation;
> > > > e.g., X,Y,Z --> U,Y,Z
>
> > > > Next, explicitly state the dimensions of ALL variables U,Y,Z,A,b,x.
>
> > > > It looks like you are just trying to solve A*x=3Db, given A and b.
>
> > > > This is not a regression problem.
>
> > > > Hope this helps.
>
> > > > Greg
>
> > > My A matrix is like that
> > > A=3D
> > > [1 =A0 X1;
> > > =A00 =A0 X1;
> > > 1 =A0 X2;
> > > 0 =A0 X2;
> > > ....
> > > 1 =A0Xn;
> > > 0 =A0Xn]
> > > b=3D
> > > [Y1;
> > > Z1;
> > > Y2;
> > > Z2;
> > > ..
> > > Yn;
> > > Zn]
>
> > > and finally
> > > x=3D[a;b]
> > > If I manually supply few vectors values for X,Y,Z I do get a& b.
> > > like
> > > x=3DA\b;
> > > but my only problem is I do not want to enter the vector values may b=
e
> > > repmat or some other command may help me. I have tried but did not
> > > have success
>
> > Look up row permutation matrices and apply them to
>
> > [ ones(n,1) X ; zeros(n,1) X ]
>
> > and
>
> > [ Y; Z]
>
> > Hope this helps.
>
> > Greg
>
> Hi Greg
> I gave the format for my A matrix, as such its not created and I have
> to create my A and b matrices. I have only given their format. Can you
> help me a bit further ?

http://en.wikipedia.org/wiki/Permutation_matrix

Hope this helps.

Greg

Subject: Setting up linear multiple regression matrix

From: fas

Date: 22 Jul, 2008 06:17:54

Message: 7 of 12

On Jul 22, 3:12 am, Greg Heath <he...@alumni.brown.edu> wrote:
> On Jul 21, 1:05 am, fas <faisalmu...@gmail.com> wrote:
>
>
>
> > On Jul 19, 2:56 am,Greg Heath<he...@alumni.brown.edu> wrote:
>
> > > On Jul 18, 7:40 am, fas <faisalmu...@gmail.com> wrote:
>
> > > > On Jul 18, 7:58 pm,Greg Heath<he...@alumni.brown.edu> wrote:
>
> > > > > On Jul 18, 2:03 am, fas <faisalmu...@gmail.com> wrote:
>
> > > > > > I have
> > > > > > A=[1 X; 0 X];
>
> > > > > X must be a row vector
>
> > > > > > b=[Y;Z];
> > > > > > where X, Y and Z are vectors
>
> > > > > It looks like you want X,Y,Z to have the same dimensions .. [ 1 n]
>
> > > > > size(A) = [ 2 n+1 ]
> > > > > size(b) = [ 2 n ]
>
> > > > > ==> size(A\b) = [ n+1 n]
>
> > > > > > and I want to do x=A\b to find two
> > > > > > coefficients x1 and x2.
>
> > > > > It does not compute.
>
> > > > > >I am finding it hard to arrange the vectors in
> > > > > > the matrix form for the required regression.
> > > > > > Any help please ?
>
> > > > > Begin by using less confusing notation;
> > > > > e.g., X,Y,Z --> U,Y,Z
>
> > > > > Next, explicitly state the dimensions of ALL variables U,Y,Z,A,b,x.
>
> > > > > It looks like you are just trying to solve A*x=b, given A and b.
>
> > > > > This is not a regression problem.
>
> > > > > Hope this helps.
>
> > > > > Greg
>
> > > > My A matrix is like that
> > > > A=
> > > > [1 X1;
> > > > 0 X1;
> > > > 1 X2;
> > > > 0 X2;
> > > > ....
> > > > 1 Xn;
> > > > 0 Xn]
> > > > b=
> > > > [Y1;
> > > > Z1;
> > > > Y2;
> > > > Z2;
> > > > ..
> > > > Yn;
> > > > Zn]
>
> > > > and finally
> > > > x=[a;b]
> > > > If I manually supply few vectors values for X,Y,Z I do get a& b.
> > > > like
> > > > x=A\b;
> > > > but my only problem is I do not want to enter the vector values may be
> > > > repmat or some other command may help me. I have tried but did not
> > > > have success
>
> > > Look up row permutation matrices and apply them to
>
> > > [ ones(n,1) X ; zeros(n,1) X ]
>
> > > and
>
> > > [ Y; Z]
>
> > > Hope this helps.
>
> > > Greg
>
> > Hi Greg
> > I gave the format for my A matrix, as such its not created and I have
> > to create my A and b matrices. I have only given their format. Can you
> > help me a bit further ?
>
> http://en.wikipedia.org/wiki/Permutation_matrix
>
> Hope this helps.
>
> Greg

I think I havn't been clear about my question.
What I want is to create a matrix of the form
A=
 [1 X1;
  0 X1;
 1 X2;
 0 X2;
.. 1 Xn;
 0 Xn]
from a vector X where X=X1,X2...Xn

secondly a vector b=
 [Y1;
Z1;
Y2;
 Z2;
 ..
Yn;
Zn]

from two vector Y and Z. I am afraid I am still unable to code it :(

Subject: Setting up linear multiple regression matrix

From: Greg Heath

Date: 22 Jul, 2008 11:27:28

Message: 8 of 12

On Jul 22, 2:17=A0am, fas <faisalmu...@gmail.com> wrote:
> On Jul 22, 3:12 am, Greg Heath <he...@alumni.brown.edu> wrote:
>
>
>
>
>
> > On Jul 21, 1:05 am, fas <faisalmu...@gmail.com> wrote:
>
> > > On Jul 19, 2:56 am,Greg Heath<he...@alumni.brown.edu> wrote:
>
> > > > On Jul 18, 7:40 am, fas <faisalmu...@gmail.com> wrote:
>
> > > > > On Jul 18, 7:58 pm,Greg Heath<he...@alumni.brown.edu> wrote:
>
> > > > > > On Jul 18, 2:03 am, fas <faisalmu...@gmail.com> wrote:
>
> > > > > > > I have
> > > > > > > A=3D[1 X; 0 X];
>
> > > > > > X must be a row vector
>
> > > > > > > b=3D[Y;Z];
> > > > > > > where X, Y and Z are vectors
>
> > > > > > It looks like you want X,Y,Z to have the same dimensions .. [ 1=
 n]
>
> > > > > > size(A) =3D [ 2 =A0n+1 ]
> > > > > > size(b) =3D [ 2 =A0n ]
>
> > > > > > =3D=3D> size(A\b) =3D [ n+1 n]
>
> > > > > > > and I want to do x=3DA\b to find two
> > > > > > > coefficients x1 and x2.
>
> > > > > > It does not compute.
>
> > > > > > >I am finding it hard to arrange the vectors in
> > > > > > > the matrix form for the required regression.
> > > > > > > Any help please ?
>
> > > > > > Begin by using less confusing notation;
> > > > > > e.g., X,Y,Z --> U,Y,Z
>
> > > > > > Next, explicitly state the dimensions of ALL variables U,Y,Z,A,=
b,x.
>
> > > > > > It looks like you are just trying to solve A*x=3Db, given A and=
 b.
>
> > > > > > This is not a regression problem.
>
> > > > > > Hope this helps.
>
> > > > > > Greg
>
> > > > > My A matrix is like that
> > > > > A=3D
> > > > > [1 =A0 X1;
> > > > > =A00 =A0 X1;
> > > > > 1 =A0 X2;
> > > > > 0 =A0 X2;
> > > > > ....
> > > > > 1 =A0Xn;
> > > > > 0 =A0Xn]
> > > > > b=3D
> > > > > [Y1;
> > > > > Z1;
> > > > > Y2;
> > > > > Z2;
> > > > > ..
> > > > > Yn;
> > > > > Zn]
>
> > > > > and finally
> > > > > x=3D[a;b]
> > > > > If I manually supply few vectors values for X,Y,Z I do get a& b.
> > > > > like
> > > > > x=3DA\b;
> > > > > but my only problem is I do not want to enter the vector values m=
ay be
> > > > > repmat or some other command may help me. I have tried but did no=
t
> > > > > have success
>
> > > > Look up row permutation matrices and apply them to
>
> > > > [ ones(n,1) X ; zeros(n,1) X ]
>
> > > > and
>
> > > > [ Y; Z]
>
> > > > Hope this helps.
>
> > > > Greg
>
> > > Hi Greg
> > > I gave the format for my A matrix, as such its not created and I have
> > > to create my A and b matrices. I have only given their format. Can yo=
u
> > > help me a bit further ?
>
> >http://en.wikipedia.org/wiki/Permutation_matrix
>
> > Hope this helps.
>
> > Greg
>
> I think I havn't been clear about my question.
> What I want is to create a matrix of the form
> A=3D
> =A0[1 =A0 X1;
> =A0 0 =A0 X1;
> =A01 =A0 X2;
> =A00 =A0 X2;
> .. 1 =A0Xn;
> =A00 =A0Xn]
> from a vector X where X=3DX1,X2...Xn
>
> secondly a vector b=3D
> =A0[Y1;
> Z1;
> Y2;
> =A0Z2;
> =A0..
> Yn;
> Zn]
>
> from two vector Y and Z. I am afraid I am still unable to code it

A =3D P1*[ ones(n,1) X ; zeros(n,1) X ];

b =3D P2* [ Y; Z];

where P1 and P2 are row permutation matrices.

http://en.wikipedia.org/wiki/Permutation_matrix

Hope you understand it now.

Greg


Subject: Setting up linear multiple regression matrix

From: fas

Date: 23 Jul, 2008 06:53:52

Message: 9 of 12

On Jul 22, 9:27 pm, Greg Heath <he...@alumni.brown.edu> wrote:
> On Jul 22, 2:17 am, fas <faisalmu...@gmail.com> wrote:
>
>
>
> > On Jul 22, 3:12 am, Greg Heath <he...@alumni.brown.edu> wrote:
>
> > > On Jul 21, 1:05 am, fas <faisalmu...@gmail.com> wrote:
>
> > > > On Jul 19, 2:56 am,Greg Heath<he...@alumni.brown.edu> wrote:
>
> > > > > On Jul 18, 7:40 am, fas <faisalmu...@gmail.com> wrote:
>
> > > > > > On Jul 18, 7:58 pm,Greg Heath<he...@alumni.brown.edu> wrote:
>
> > > > > > > On Jul 18, 2:03 am, fas <faisalmu...@gmail.com> wrote:
>
> > > > > > > > I have
> > > > > > > > A=[1 X; 0 X];
>
> > > > > > > X must be a row vector
>
> > > > > > > > b=[Y;Z];
> > > > > > > > where X, Y and Z are vectors
>
> > > > > > > It looks like you want X,Y,Z to have the same dimensions .. [ 1 n]
>
> > > > > > > size(A) = [ 2 n+1 ]
> > > > > > > size(b) = [ 2 n ]
>
> > > > > > > ==> size(A\b) = [ n+1 n]
>
> > > > > > > > and I want to do x=A\b to find two
> > > > > > > > coefficients x1 and x2.
>
> > > > > > > It does not compute.
>
> > > > > > > >I am finding it hard to arrange the vectors in
> > > > > > > > the matrix form for the required regression.
> > > > > > > > Any help please ?
>
> > > > > > > Begin by using less confusing notation;
> > > > > > > e.g., X,Y,Z --> U,Y,Z
>
> > > > > > > Next, explicitly state the dimensions of ALL variables U,Y,Z,A,b,x.
>
> > > > > > > It looks like you are just trying to solve A*x=b, given A and b.
>
> > > > > > > This is not a regression problem.
>
> > > > > > > Hope this helps.
>
> > > > > > > Greg
>
> > > > > > My A matrix is like that
> > > > > > A=
> > > > > > [1 X1;
> > > > > > 0 X1;
> > > > > > 1 X2;
> > > > > > 0 X2;
> > > > > > ....
> > > > > > 1 Xn;
> > > > > > 0 Xn]
> > > > > > b=
> > > > > > [Y1;
> > > > > > Z1;
> > > > > > Y2;
> > > > > > Z2;
> > > > > > ..
> > > > > > Yn;
> > > > > > Zn]
>
> > > > > > and finally
> > > > > > x=[a;b]
> > > > > > If I manually supply few vectors values for X,Y,Z I do get a& b.
> > > > > > like
> > > > > > x=A\b;
> > > > > > but my only problem is I do not want to enter the vector values may be
> > > > > > repmat or some other command may help me. I have tried but did not
> > > > > > have success
>
> > > > > Look up row permutation matrices and apply them to
>
> > > > > [ ones(n,1) X ; zeros(n,1) X ]
>
> > > > > and
>
> > > > > [ Y; Z]
>
> > > > > Hope this helps.
>
> > > > > Greg
>
> > > > Hi Greg
> > > > I gave the format for my A matrix, as such its not created and I have
> > > > to create my A and b matrices. I have only given their format. Can you
> > > > help me a bit further ?
>
> > >http://en.wikipedia.org/wiki/Permutation_matrix
>
> > > Hope this helps.
>
> > > Greg
>
> > I think I havn't been clear about my question.
> > What I want is to create a matrix of the form
> > A=
> > [1 X1;
> > 0 X1;
> > 1 X2;
> > 0 X2;
> > .. 1 Xn;
> > 0 Xn]
> > from a vector X where X=X1,X2...Xn
>
> > secondly a vector b=
> > [Y1;
> > Z1;
> > Y2;
> > Z2;
> > ..
> > Yn;
> > Zn]
>
> > from two vector Y and Z. I am afraid I am still unable to code it
>
> A = P1*[ ones(n,1) X ; zeros(n,1) X ];
>
> b = P2* [ Y; Z];
>
> where P1 and P2 are row permutation matrices.
>
> http://en.wikipedia.org/wiki/Permutation_matrix
>
> Hope you understand it now.
>
> Greg

I have come to realize that constructing P1 and P2 is as time
consuming as putting the values manually, if I am not wrong ?

Subject: Setting up linear multiple regression matrix

From: Tom Lane

Date: 23 Jul, 2008 13:20:39

Message: 10 of 12

>> > I think I havn't been clear about my question.
>> > What I want is to create a matrix of the form
>> > A=
>> > [1 X1;
>> > 0 X1;
>> > 1 X2;
>> > 0 X2;
>> > .. 1 Xn;
>> > 0 Xn]
>> > from a vector X where X=X1,X2...Xn
>>
>> > secondly a vector b=
>> > [Y1;
>> > Z1;
>> > Y2;
>> > Z2;
>> > ..
>> > Yn;
>> > Zn]
>>
>> > from two vector Y and Z. I am afraid I am still unable to code it

I have not followed this until now, but it seems like you want to do the
following:

x = (1:5)'; y = 10*x; z = 100*x;
col1 = repmat([1;0],5,1); % column of alternating 1 and 0
col2 = [x'; x']; col2 = col2(:); % column of x values repeated twice
a = [col1 col2]
b = [y'; z']; % matrix with y in row 1, z in row 2
b = b(:) % column of interleaved y and z

-- Tom


Subject: Setting up linear multiple regression matrix

From: fas

Date: 24 Jul, 2008 00:21:54

Message: 11 of 12

On Jul 23, 11:20 pm, "Tom Lane" <tl...@mathworks.com> wrote:
> >> > I think I havn't been clear about my question.
> >> > What I want is to create a matrix of the form
> >> > A=
> >> > [1 X1;
> >> > 0 X1;
> >> > 1 X2;
> >> > 0 X2;
> >> > .. 1 Xn;
> >> > 0 Xn]
> >> > from a vector X where X=X1,X2...Xn
>
> >> > secondly a vector b=
> >> > [Y1;
> >> > Z1;
> >> > Y2;
> >> > Z2;
> >> > ..
> >> > Yn;
> >> > Zn]
>
> >> > from two vector Y and Z. I am afraid I am still unable to code it
>
> I have not followed this until now, but it seems like you want to do the
> following:
>
> x = (1:5)'; y = 10*x; z = 100*x;
> col1 = repmat([1;0],5,1); % column of alternating 1 and 0
> col2 = [x'; x']; col2 = col2(:); % column of x values repeated twice
> a = [col1 col2]
> b = [y'; z']; % matrix with y in row 1, z in row 2
> b = b(:) % column of interleaved y and z
>
> -- Tom

Thanks Tom. This is exactly what I want.

Subject: Setting up linear multiple regression matrix

From: Greg Heath

Date: 24 Jul, 2008 00:56:08

Message: 12 of 12

On Jul 23, 9:20=A0am, "Tom Lane" <tl...@mathworks.com> wrote:
> >> > I think I havn't been clear about my question.
> >> > What I want is to create a matrix of the form
> >> > A=3D
> >> > =A0[1 =A0 X1;
> >> > =A0 0 =A0 X1;
> >> > =A01 =A0 X2;
> >> > =A00 =A0 X2;
> >> > .. 1 =A0Xn;
> >> > =A00 =A0Xn]
> >> > from a vector X where X=3DX1,X2...Xn
>
> >> > secondly a vector b=3D
> >> > =A0[Y1;
> >> > Z1;
> >> > Y2;
> >> > =A0Z2;
> >> > =A0..
> >> > Yn;
> >> > Zn]
>
> >> > from two vector Y and Z. I am afraid I am still unable to code it
>
> I have not followed this until now, but it seems like you want to do the
> following:
>
> x =3D (1:5)'; y =3D 10*x; z =3D 100*x;
> col1 =3D repmat([1;0],5,1); =A0 % column of alternating 1 and 0
> col2 =3D [x'; x']; col2 =3D col2(:); =A0 % column of x values repeated tw=
ice
> a =3D [col1 col2]
> b =3D [y'; z']; =A0% matrix with y in row 1, z in row 2
> b =3D b(:) =A0% column of interleaved y and z

Nice use of (:)!

Greg

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
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 Disclaimer prior to use.
Related Topics