Converting Alternative Scientific Notation to MATLAB

5 ビュー (過去 30 日間)
Stephen Biel
Stephen Biel 2020 年 11 月 17 日
編集済み: Stephen23 2020 年 11 月 18 日
I have a file with these example numbers I have imported as strings. I can't import as numbers because they come up as NaN.
-5.769-2
3.9984-2
4.568450
These are the 3 variations of numbers in the file
I want to convert these imported strings to MATLAB double, but I get NaN for the first 2 variations.
str2double('-5.769-2') = NaN
str2double('3.9984-2') = NaN
str2double('4.568450') = 4.568450
I want to get the following
-5.769-2 = -5.769e-2
3.9984-2 = 3.9984e-2
Thanks for your assistance.
  4 件のコメント
James Tursa
James Tursa 2020 年 11 月 17 日
You haven't answered my question about spacing. Are the numbers right next to each other, each in 8 columns exactly? Or ...? Can you post a sample of the lines? This would affect how people would answer your question.
Stephen Biel
Stephen Biel 2020 年 11 月 17 日
編集済み: Stephen23 2020 年 11 月 18 日
Here is an example. The number data at the right of the row is 3 coordinate points that are 8 characters long. Thx.
GRID 15123 .272603922.913396.501789
GRID 15124 .334725822.913396.358268
GRID 15125 .281283322.913396.223329
GRID 15126 .148712722.913396.161716
GRID 15127 1.1008-222.913396.207708
GRID 15128 4.66672 22.9133910.39098
GRID 15129 4.71135 22.9133910.5398
GRID 15130 4.85003822.9133910.60985
GRID 15131 4.99701322.9133910.55691

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2020 年 11 月 17 日
format long
S = {
'-5.769-2'
'3.9984-2'
'4.568450'
};
str2double(regexprep(S, '([-+]\d+)$', 'e$1'))
ans = 3×1
-0.057690000000000 0.039984000000000 4.568450000000000
  1 件のコメント
Stephen Biel
Stephen Biel 2020 年 11 月 18 日
Dear Sir,
You are a genius! Very elegant! Thx.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by