Search tips

Search tips

# Discussion Groups | Matlab DSP | Matrix to Vector

Technical discussion about Matlab and issues related to Digital Signal Processing.

Is this thread worth a thumbs up?

0

# Matrix to Vector - worldtranquility - May 5 18:14:00 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.

# Re: Matrix to Vector - georges zaki - May 6 8:47:00 2005

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 écrit:
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

_____________________________________
/groups/matlab/1.php

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

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

Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail

# Re: Matrix to Vector - Ahmad El-Saied - May 6 9:11:00 2005

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

# Re: Matrix to Vector - Juan de Dios Santander Vela - May 6 10:37:00 2005

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. Físicas, Ingeniero en Electrónica
Doctorando en Tecnologías Multimedia
Becario Predoctoral del Instituto de Astrofísica de Andalucía

Woody Allen: ¡Ojalá Dios me diera una clara señal! Como hacer un gran
depósito a mi nombre en un banco suizo...

# Re: Matrix to Vector - Tolga Özkurt - May 6 10:52:00 2005

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. __________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail

# Re: Matrix to Vector - Roberto Henry - May 6 19:04:00 2005

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.

# Re: Matrix to Vector - Roberto Henry - May 6 20:36:00 2005

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.