Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does x = x(:) mean in matlab, where x is a vector?

Tags:

matlab

This is a hard question to google. I am new to Matlab and have seen the following statement, but I can't see how it does anything. What doe x = x(:) do?

like image 207
zebra Avatar asked Jan 15 '12 02:01

zebra


1 Answers

: is the colon operator. In this context, it reshapes x to a one-dimensional column vector.

So this code:

x = [ 1 3
      2 4 ];

x = x(:);

disp(x)

results in:

1
2
3
4
like image 114
Oliver Charlesworth Avatar answered Oct 05 '22 02:10

Oliver Charlesworth