Matlab Science Note Release

I have a problem where an 8-digit string, such as "313397E9", is passed to excel, then read as the number "313397000000000" or "3.133970e + 014".

This is then read by Matlab and recognized as a number, not a string. What would be the easiest way to convert it to an 8-digit string?

Thanks in advance for your help.

+5
source share
1 answer

Regular expressions for salvation! You can use REGEXPREP to convert trailing zeros to Ex, where x is the number of zeros you just replaced.

%# 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

, nn - , btw, .

+5

All Articles