【问题标题】:append digits to a number - Matlab将数字附加到数字 - Matlab
【发布时间】:2012-04-24 05:22:57
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: matlab numbers append digits


    【解决方案1】:

    如果你取data 的以 10 为底的对数,你可以知道你需要乘以 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
    

    【讨论】:

      猜你喜欢
      • 2011-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-17
      • 2016-06-11
      • 2012-10-05
      • 1970-01-01
      • 2013-08-19
      相关资源
      最近更新 更多