【发布时间】: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
我有一列只有whole numbers,我需要在前面附加一个数字(比如11)-
data = (1:1300000)';
% append 11 to these numbers
newdata = [111 ; 112 ; 113 ; 114 ; ......]
有没有办法不使用str2num(由于速度问题)?谢谢。
【问题讨论】:
标签: matlab numbers append digits
如果你取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
【讨论】: