フィルターのクリア

Replace "-" with "E-" in output file

2 ビュー (過去 30 日間)
Etienne
Etienne 2017 年 2 月 14 日
コメント済み: Etienne 2017 年 2 月 14 日
Hi All
I have an output file that printed some numbers incorrectly, for instance, 1.7865271465-119 should be 1.7865271465E-119. I do not have control with regards to the output format. My question is how can I replace the "-" with "E-"? I have tried regexprep but it replaces the two numbers each side of the minus sign as well. Any help will be appreciated.
Regards
Etienne
  1 件のコメント
Adam
Adam 2017 年 2 月 14 日
Can't you just do it in a standard text editor with a find & replace?

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

採用された回答

per isakson
per isakson 2017 年 2 月 14 日
編集済み: per isakson 2017 年 2 月 14 日
This does it
>> regexprep( '1.7865271465-119', '([\d\.]+)\-(\d+)', '$1E-$2' )
ans =
1.7865271465E-119
But it doesn't work with '1.7865271465+119'. This works with plus or minus
>> regexprep( '1.7865271465+119', '([\d\.]+)([\-\+])(\d+)', '$1E$2$3' )
ans =
1.7865271465E+119
  1 件のコメント
Etienne
Etienne 2017 年 2 月 14 日
Brilliant, thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by