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 件のコメント

PANDIAN` NITHYANANDAM
PANDIAN` NITHYANANDAM 2012 年 7 月 20 日
thanks sir,
but how to convert 2d double array into a vector.

サインインしてコメントする。

 採用された回答

Jan
Jan 2012 年 7 月 20 日
編集済み: Jan 2012 年 7 月 20 日

4 投票

Several methods:
X = rand(10, 20);
V1 = X(:);
V2 = reshape(X, 1, []);
V3 = reshape(X, numel(X), 1);

その他の回答 (1 件)

Hanoh Beizer
Hanoh Beizer 2014 年 7 月 20 日
編集済み: Hanoh Beizer 2014 年 7 月 20 日

0 投票

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 件のコメント

Jan
Jan 2014 年 8 月 2 日
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 2014 年 10 月 9 日
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

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

質問済み:

2012 年 7 月 20 日

コメント済み:

Anu
2014 年 10 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by