Just reshape the matrix/verctor to a single row :
v = reshape(v,1, [])
It will also leave a vector of the right shape unchanged.
If you go to the documentation on reshape, the 1 means 1 row, and the [] means as many columns as needed given the size of v.
The full function:
function v = RowIt(v)
v = reshape(v,1,[]);
end
Comparing with @Adriaan answer
Reshape version:
v = rand(5000*5000, 1);
tic;
for i=1:100000
b = reshape(v,1, []);
end
toc
Elapsed time is 0.347047 seconds.
(:).' version: this answer
v = rand(5000*5000, 1);
tic
for i=1:100000
b = v(:).';
end
toc
Elapsed time is 0.082710 seconds
So @Adriaan's solution is clearly faster, probably due to function call overload cost. You must know that no data is copied during this operation, except if you modify it (MATLAB copy on modify), so it is really fast anyway.
The advantage is for reshape when you need to customize things, like:
a = rand(10, 10)
size(reshape(a, 2,[]))
ans =
2 50