conversion of 2d array in to vector

27 vues (au cours des 30 derniers jours)
PANDIAN` NITHYANANDAM
PANDIAN` NITHYANANDAM le 20 Juil 2012
Commenté : Anu le 9 Oct 2014
hai matlab users
i have a 2d array double matrix ; i would like to convert it to vector.
2d array to vector.
since dec2bin not working on arrays; i would like to convert the array in to vector. can any one say, how to convert a 2d array into a vector with an example or the command to do that
  1 commentaire
PANDIAN` NITHYANANDAM
PANDIAN` NITHYANANDAM le 20 Juil 2012
thanks sir,
but how to convert 2d double array into a vector.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 20 Juil 2012
Modifié(e) : Jan le 20 Juil 2012
Several methods:
X = rand(10, 20);
V1 = X(:);
V2 = reshape(X, 1, []);
V3 = reshape(X, numel(X), 1);

Plus de réponses (1)

Hanoh Beizer
Hanoh Beizer le 20 Juil 2014
Modifié(e) : Hanoh Beizer le 20 Juil 2014
That's what I did with my picture:
sz=size(pic);
num=sz(1)*sz(2);
pic_vec=zeros(num);
count=1;
for i=1:sz(1)
for j=1:sz(2)
pic_vec(count)=pic(i,j);
count=count+1;
end
end
  2 commentaires
Jan
Jan le 2 Août 2014
zeros(num) creates a num*num matrix. I assume you mean zeros(num, 1). Anyway, the loopless pic_vec=pic(:) is much faster.
Anu
Anu le 9 Oct 2014
HERE IS THE CODE IN MATLAB TO CONVERT 2D MATRIX TO A VECTOR:
sz=size(pic);
num=sz(1)*sz(2);
pic_vec=zeros(1,num);
for i=1:sz(1)
for j=1:sz(2)
pic_vec(1,(i-1)*sz(2)+j)=pic(i,j)
end
end

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by