vectors from array

What is the best way to create vectors from columns of an array?

 채택된 답변

David Young
David Young 2011년 12월 14일

0 개 추천

vector = array(:, column_number)

댓글 수: 5

Gary
Gary 2011년 12월 14일
Thanks. How do I use a for loop to create three vectors from a n array with three colums.
Paulo Silva
Paulo Silva 2011년 12월 14일
a=randi(5,5,3) %sample array
for n=1:size(a,2)
b{n}=a(:,n);
end
c=1; %choose the column
v=b{c} %get the vector of that column
David Young
David Young 2011년 12월 14일
In general, how you do this depends on what you are going to do with the vectors. It may be simplest to leave the original array as it is, and simple use array(:, column_number) at the point in your program where you need the vector on its own.
Gary
Gary 2011년 12월 14일
How can I get separate vectors such as V1, V2 and V3. Thanks
Paulo Silva
Paulo Silva 2011년 12월 14일
see my Answer and http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paulo Silva
Paulo Silva 2011년 12월 14일

0 개 추천

a=randi(5,3,5) %sample array
%put all columns of the array in diferent cells
b=arrayfun(@(x)a(:,x),1:size(a,2),'uni',0);
c=1; %choose the column
v=b{c} %get the vector of that column

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

2011년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by