conversion of matrix into vector

2 次查看(过去 30 天)
I made an algorithm of conversion of a matrix for a vector of column but it just works for the matrix 3*4. I want that it work on is important dimension(size). All the dimensions(size)! How I make? the code :
x=[1 2 3 0;4 5 6 0;7 8 9 0];
y=x(:,1);
m=2;
while m<5
y=[y;x(:,m)];
m=m+1;
end

采纳的回答

Wayne King
Wayne King 2013-4-26
编辑:Wayne King 2013-4-26
Is this important that you write yourself? Because there is a reshape() function
x = randn(10,10);
y = reshape(x,100,1);
If it is important, then just starting from what you have, how about
x = randn(10,10);
y=x(:,1);
m=2;
while m<= size(x,2)
y=[y;x(:,m)];
m=m+1;
end
  1 个评论
krak
krak 2013-4-26
编辑:krak 2013-4-26
Thank you for your answer! I have an image (any image) and I want to convert her in a vector of columns! It is the only algorithm which I found! I would like of your help :)

请先登录,再进行评论。

更多回答(2 个)

sammar
sammar 2013-4-26
hey krak try this way if that what you want
x=[1 2 3 0;4 5 6 0;7 8 9 0]; >> B = reshape(x.',1,[]);
  1 个评论
krak
krak 2013-4-26
hey sammar , Yes the function reshape, but how I have to use him under matlab? Thank you for your answer:)

请先登录,再进行评论。


Jim
Jim 2013-4-26
Just x(:)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by