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 Exchange에서 Data 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