MATLAB Answers

## conversion of matrix into vector

Asked by krak

### krak (view profile)

on 26 Apr 2013
Accepted Answer by Wayne King

### Wayne King (view profile)

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

## Products

No products are associated with this question.

## 3 Answers

### Wayne King (view profile)

Answer by Wayne King

### Wayne King (view profile)

on 26 Apr 2013
Edited by Wayne King

### Wayne King (view profile)

on 26 Apr 2013
Accepted answer

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```

krak

### krak (view profile)

on 26 Apr 2013

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 :)

Answer by sammar

### sammar (view profile)

on 26 Apr 2013

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,[]);

krak

### krak (view profile)

on 26 Apr 2013

hey sammar , Yes the function reshape, but how I have to use him under matlab? Thank you for your answer:)

Answer by Jim

### Jim (view profile)

on 26 Apr 2013

Just x(:)

#### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today