# Matrix to Vector

Started by May 5, 2005
Hi all,
I would like to know if there is a MATLAB function for converting a 2D
matrix to a vector (ie, append all the elements of the rows at the end
of the first one)so that a MxN matrix is converted into a MNx1 or 1xMN
vector.
Thanks
Warm Regards
Ciao.

Hi
yes,
1- if you have a 2d matrix y so you can write x =  y ( : ) ;
2- You can use more general command which is reshape.  search in matlab help on it.

George

worldtranquility <w...@yahoo.com> a rit:
Hi all,
I would like to know if there is a MATLAB function for converting a 2D
matrix to a vector (ie, append all the elements of the rows at the end
of the first one)so that a MxN matrix is converted into a MNx1 or 1xMN
vector.
Thanks
Warm Regards
Ciao.

NEW!  You can now post a message or access and search the archives of this group on DSPRelated.com:
http://www.dsprelated.com/groups/matlab/1.php

_____________________________________

_____________________________________

Archives:  http://www.dsprelated.com/groups/matlab/1.php

To Post:  Send an email to m...@yahoogroups.com

Other DSP Related Groups: http://www.dsprelated.com/groups.php

Douvrez le nouveau

Hi Ciao,
i think that the function reshape suits your
needs , for example:

a=[1 2 3 ; 4 5 6; 7 8 9];
b=reshape(a,9,1);

you can use also some function like transpose ... i
think that these 2 functions are enough to make any
order for the matrix

--- worldtranquility <worldtranquility@worl...>
wrote:
---------------------------------
Hi all,
I would like to know if there is a MATLAB function for
converting a 2D
matrix to a vector (ie, append all the elements of the
rows at the end
of the first one)so that a MxN matrix is converted
into a MNx1 or 1xMN
vector.
Thanks
Warm Regards
Ciao. To ___________________________________________________________
Yahoo! Messenger - want a free and easy way to contact your friends online? http://uk.messenger.yahoo.com

El 06/05/2005, a las 0:14, worldtranquility escribi

> I would like to know if there is a MATLAB function for converting a 2D
> matrix to a vector (ie, append all the elements of the rows at the end
> of the first one)so that a MxN matrix is converted into a MNx1 or 1xMN
> vector.

Say A is your MxN matrix.

B = reshape(A, prod(size(A)), 1) is a MNx1 vector
C = reshape(A, 1, prod(size(A))) is a 1xMN vector

--
Juan de Dios Santander Vela
Diplomado en CC. Ficas, Ingeniero en Electrica
Doctorando en Tecnologs Multimedia
Becario Predoctoral del Instituto de Astrofica de Andaluc

Woody Allen: OjalDios me diera una clara sel! Como hacer un gran
depito a mi nombre en un banco suizo...

Hey Clao,
Use colon operator. Say if your matrix is A and
convert it to a vector B :

B=A(:);

Regards,

tolga esat ozkurt

--- worldtranquility <worldtranquility@worl...>
wrote:
> Hi all,
> I would like to know if there is a MATLAB function
> for converting a 2D
> matrix to a vector (ie, append all the elements of
> the rows at the end
> of the first one)so that a MxN matrix is converted
> into a MNx1 or 1xMN
> vector.
> Thanks
> Warm Regards
> Ciao.
__________________________________

Dear Ciao:
test this way:
>>[M,N]=size(A);
>> AR = reshape(A',1,M*N)
Best regards

Henry

Date: Thu, 05 May 2005 22:14:33 -0000
From: "worldtranquility" <
w...@yahoo.com>
Subject: Matrix to Vector

Hi all,
I would like to know if there is a MATLAB function for converting a 2D
matrix to a vector (ie, append all the elements of the rows at the end
of the first one)so that a MxN matrix is converted into a MNx1 or 1xMN
vector.
Thanks
Warm Regards
Ciao.

Dear Ciao:
test this way:
>>[M,N]=size(A);
>> AR = reshape(A',1,M*N)
Or you can use this new function because reshape is a built-in function and you can not see the code.

function vect= mat2vec(A)
[M,N]=size(A);
L=M*N;
for i=1:M
vect(i*N-N+1:i*N)=A(i,:);
end
Best regards

Henry

Date: Thu, 05 May 2005 22:14:33 -0000
From: "worldtranquility" <
w...@yahoo.com>
Subject: Matrix to Vector

Hi all,
I would like to know if there is a MATLAB function for converting a 2D
matrix to a vector (ie, append all the elements of the rows at the end
of the first one)so that a MxN matrix is converted into a MNx1 or 1xMN
vector.
Thanks
Warm Regards
Ciao.