I am confused on how to vectorize the given code in Octave. Someone please lend me help. Thank you
function Z = expand(xx,ncol)
xx = xx(:);
Z = zeros(length(xx), ncol);
for i = 1:ncol
Z(:,i) = xx;
endfor
f = 1:5
endfunction
Calling the function in the command window:
expand(f,2)
Result:
f =
1 2 3 4 5
ans =
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9