将数字附加到数字 - Matlab

Mad*_*ddy 1 matlab numbers append digits

我只有一个列whole numbers,我需要11在前面添加一个数字(比如说) -

data = (1:1300000)';
% append 11 to these numbers

newdata = [111 ;  112 ; 113 ; 114 ; ......]
Run Code Online (Sandbox Code Playgroud)

有没有办法不使用str2num(由于速度问题)?谢谢.

Jon*_*nas 5

如果你取10的基数data,你可以找出你需要多少乘以11,这样你就可以把它变成一个简单的加法.

%# create some test data
data = [1 22 123];

%# add 11*10^x to data so that the two ones end up in front of the number
newData = 11*10.^(floor(log10(data))+1)+data

newData =
         111        1122       11123
Run Code Online (Sandbox Code Playgroud)