简体   繁体   English

将数字附加到数字-Matlab

[英]append digits to a number - Matlab

I have a column with only whole numbers in it, to which I need to append a number (say 11 ) at the front - 我有一列只包含whole numbers的列,我需要在其前面附加一个数字(例如11 )-

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

newdata = [111 ;  112 ; 113 ; 114 ; ......]

Is there a way to do it without using str2num (due to speed issues) ? 有没有办法不用str2num来做到这str2num (由于速度问题)? Thanks. 谢谢。

If you take the base 10 logarithm of data , you can find out by how much you have to multiply 11 so that you can turn this into a simple addition. 如果采用以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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM