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.
Reply by Roberto Henry●May 6, 20052005-05-06
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.
Reply by ●May 6, 20052005-05-06
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.
__________________________________
Reply by Juan de Dios Santander Vela●May 6, 20052005-05-06
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...
Reply by Ahmad El-Saied●May 6, 20052005-05-06
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
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
Reply by georges zaki●May 6, 20052005-05-06
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
_____________________________________ Note: If you do a simple "reply"
with your email client, only the author of this message will receive your
answer. You need to do a "reply all" if you want your answer to be
distributed to the entire group.
_____________________________________ About this discussion group:
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.