Split a char without spaces and arbitrarily characters
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello together,
I need your help to split my text. As you can see, I have a char with the name "text" (in my project i will read this row from a textfile).
Now I have to split this row into 13 parts. Sometimes a space is in between, sometimes not. I have problems to split the parts, when exponential notation is given together.
My consideration was to split the text with strsplit after each space AND after the character "E***". The * stands for any characters after the E.
For example, the first 4 cells should be like this: 17575 3.10705E+00 -7.07230E+01 -1.77433E-01.
Thansk for your help!
Mcihael
text = sprintf(' 17575 3.10705E+00-7.07230E+01-1.77433E-01-2.72479E-05-7.19082E-06-9.65426E-06 1.70247E-04 4.89104E-05 3.56048E-05 3.71071E+01-3.38230E+01-1.77433E-01');
댓글 수: 0
채택된 답변
Stephen23
2022년 11월 16일
편집: Stephen23
2022년 11월 16일
format long G
txt = ' 17575 3.10705E+00-7.07230E+01-1.77433E-01-2.72479E-05-7.19082E-06-9.65426E-06 1.70247E-04 4.89104E-05 3.56048E-05 3.71071E+01-3.38230E+01-1.77433E-01';
vec = sscanf(txt,'%f') % the simplest and most efficient approach is to convert to numeric
rgx = '\s*[-+]?\d+\.?\d*(E[-+]\d+)?';
spl = regexp(txt,rgx,'match') % if you really want to fiddle around with text
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!