简体   繁体   English

matlab 科学计数法问题

[英]matlab scientific notation issue

I have an issue where an 8-digit string such as '313397E9' is being passed into excel, then read as the number '313397000000000', or '3.133970e+014'.我有一个问题,其中一个 8 位字符串(例如“313397E9”)被传递到 excel,然后读取为数字“313397000000000”或“3.133970e+014”。

This is then being read by Matlab and recognized as the number, not the string.然后由 Matlab 读取并识别为数字,而不是字符串。 What would be the easiest way to convert it back to the 8-digit string?将其转换回 8 位字符串的最简单方法是什么?

Thanks in advance for all your help.提前感谢您的所有帮助。

Regular expressions to the rescue!正则表达式来拯救! You can use REGEXPREP to convert the trailing zeros into Ex, where x is the number of zeros you just replaced.您可以使用REGEXPREP将尾随零转换为 Ex,其中 x 是您刚刚替换的零的数量。

%# convert the number to a string
nn = num2str(3.133970e+014)

nn =
313397000000000

%# replace zeros using regexprep
regexprep(nn,'([0]*)','E${num2str(length($1))}')
ans =
313397E9

This also works if nn is a cell array of strings, btw, so you can convert your list of numbers in one go.如果nn是一个字符串元胞数组,这也适用,顺便说一句,因此您可以将数字列表转换为一个 go。

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

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