Split a char without spaces and arbitrarily characters
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Michael Eissler
el 16 de Nov. de 2022
Comentada: Michael Eissler
el 16 de Nov. de 2022
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 comentarios
Respuesta aceptada
Stephen23
el 16 de Nov. de 2022
Editada: Stephen23
el 16 de Nov. de 2022
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
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!