如何将数字/整数值写入10的幂,例如1000为10 ^ 3?我正在编写代码,其输出是一个非常大的数字字符串。我的longEng格式输出是:
4.40710646596169e+018
16.9749211806197e+186
142.220634811050e+078
508.723835280617e+204
1.15401317731033e-177
129.994388899690e+168
14.3008811642810e+153
1.25899227268954e+165
24.1450064703939e+150
627.108997290435e+144
2.03728822649372e+177
339.903986115177e-066
150.360900017430e+183
5.39003779219462e+135
183.893417489826e+198
648.544709490386e+045
19.7574461055182e+198
3.91455750674308e+102
6.41548629454028e-114
70.4943280639616e+096
19.7574461055182e+198
3.11450571506133e-009
249.857950606210e+093
4.64921904682151e+180
750.343029004712e+147
我希望这些结果的格式为10的幂,这样我就可以轻松地为下一个函数进行算术运算。
答案 0 :(得分:0)
如果您只想以科学格式打印数据,Matlab本身就可以为您完成此操作。 如果您能够获得科学记数法表格
a * 10^b,
即,获得系数a和指数b,你可以先得到b为:
b = floor(log10(abs(x)));
然后a as:
a = x * 10^(-b);
答案 1 :(得分:0)
你可以写format shortE
并看到你的输出:
4.4071e+18
1.6975e+187
1.4222e+80
5.0872e+206
答案 2 :(得分:0)
根据我的理解,您希望记下您的电话号码,例如: 4.40710646596169e + 018并将其拆分为:
4.40710646596169和018一旦你将它们分开,你可以按照自己的意愿进行操作。
你甚至可以加入他们看起来像:4.40710646596169 ^ 018如果你愿意(虽然看起来他们会成为字符串,因此对数字的数学运算将是NAN)。
由于e代表电源10并且存在于您列出的所有数字中,因此这是一个包含许多解决方案的简单过程,此处为一个。
% format long is very important otherwise it will appear to you that you have
%lost precision. MATLAB hides precision from view to save screen space and to
%produce less confusing results to the viewer. (the precision is still there but
%with format long you will be able to see it.
format long
x = 4.40710646596169e+018;
%convert your number into a string, this will allow you to split the number based
%on the always present e+ 'delimiter' (not really a delimiter but looks like one')
s = num2str(x);
%use strsplit to perform the split in the required place. it will output a 1x2
%cell
D = strsplit(s, {'e+'});
%extract each cell to a separate variable. in fact D{1} can be directly used for
%the input of the next function.
D11 = D{1};
D22 = D{2};
%convert the separated strings back into numbers with double precision (keep
%maintin value accuracy)
D1 = str2double(D11)
D2 = str2double(D22)
为了对整个列向量执行此操作,只需使用for循环迭代所有数字。