如何在 MATLAB 中将"8.1076e-05"转换为 0.0000811?



在我的字符串数组中,我有一些值,比如"8.1076e-05";。做空时遇到的问题。我使用代码FinalHierarchy = sortrows(B, 3, 'descend');来进行缩写,结果如下。

"FC624  "    "0.010686"     "9.5329e-05"
"FC642  "    "0.0044959"    "8.2636e-05"
"FC621  "    "0.0090886"    "8.1076e-05"
"FC622  "    "0.0086253"    "7.6943e-05"
"FC623  "    "0.0080882"    "7.2152e-05"
"FC643  "    "0.0028437"    "5.2267e-05"
"FC646  "    "0.0025469"    "4.6813e-05"
"FC644  "    "0.0012072"    "2.2189e-05"
"FC122  "    "0.0073847"    "0.00077775"
"FC142  "    "0.010012"     "0.00072479"
"FC131  "    "0.0094101"    "0.00071951"
"FC121  "    "0.0068294"    "0.00071926"
"FC521  "    "0.0095355"    "0.00069401"
"FC112  "    "0.0087711"    "0.00063404"
"FC111  "    "0.008607"     "0.00062218"
"FC531  "    "0.0058125"    "0.00055105"
"FC141  "    "0.0074634"    "0.0005403" 
"FC228  "    "0.0098074"    "0.00049734"
"FC224"      "0.009434"     "0.0004784" 
"FC221  "    "0.0092251"    "0.00046782"
"FC225"      "0.0088874"    "0.00045069"

从上面可以看出,MATLAB已经考虑了值2.2189e-05大于0.00077775。我想背后的原因是,MATLAB比较了2.21890.00077775。这是因为列是一个字符串。在我的计算中,column 2column 3是双的,但当我将它们与字符串column 1连接为'B'时,它就变成了字符串。我想如果2.2189e-05保持为0.00002219,可能会有一个非常简单的解决方案。我尝试将format更改为longG,但问题仍然存在。有人能提出解决这个问题的办法吗?

正如您所说,这是因为您的元素是字符串。所以你可以做的是:

% Sort the column after having casted it to double
[~, idx] = sort(str2double(B(:, 3)), 'descend');
% Apply the sorting to the initial matrix
FinalHierarchy  = B(idx, :);

相关内容

  • 没有找到相关文章

最新更新