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

**Is this thread worth a thumbs up?**

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
Ã©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

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

Ahmad El-Saied

--- 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

> 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...

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

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

[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.