Here is the vector version, which is the idiomatic Matlab:
However, it actually does a linear scan 4 times. If you really want to increase efficiency, write the C mex function.
V = cell(size(U));
V{U==0} = '0';
V{U==1} = '1';
V{U==2} = '12';
V{U==3} = '123';
Edit:
The gnovice solution is far superior. See above.
source
share