distinguishing exponential (e) from other characters with regexp

조회 수: 5 (최근 30일)
sermet
sermet 2017년 5월 24일
편집: Stephen23 2017년 5월 24일
omega=
'-1.86265e-09</'
'-1.86265e-09</'
'-1.74623e-09</'
'-1.74623e-09</'
'-1.62981e-09</'
'-1.62981e-09</'
'-1.74623e-09</'
'-1.62981e-09</'
'-1.86265e-09</'
'-1.62981e-09</'
'-1.86265e-09</'
%11x1 cell
I run the below code to extract only numeric parts of rows;
omega= regexp(omega,'[+-]?\d+\.?\d*', 'match');
But it also remove "e". How can I modify above code to get e as a numeric part?

채택된 답변

Stephen23
Stephen23 2017년 5월 24일
편집: Stephen23 2017년 5월 24일
'[+-]?\d+\.?\d*([eE][+-]?\d+)?'
PS: If each string contains just one number then you should consider using the 'once' option as well, as this simplifies the outputs:
regexp(... 'match','once');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by