SELECT SPECIFIC VALUES FROM AN ARRAY
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Juan Pablo Guamn Bernal
el 3 de Nov. de 2020
Comentada: Juan Pablo Guamn Bernal
el 9 de Nov. de 2020
I have an array with this information from a FEM simulation, I need to build a data base from several iterations on the simulation, nevertheless I am having hard time to get the specific value number, however I was able to build this array where I have the results but I need just the first number number, like 0,78, 47,08, -0,83......1,27, I will really appreciate any hepl, best regards
' 0.78 sec'
' 47.08 oC(116.75 oF)'
' 27.84 oC( 82.10 oF)'
' -0.83 J/cm2-sec (-5.07e-03 Btu/in2-sec)'
' -8.86 J/cm2 (-5.42e-02 Btu/in2)'
' 0.44 J/cm2-sec (2.70e-03 Kbtu/in2-sec)'
' 4.71 J/cm2 (2.89e-02 Btu/in2)'
' 25.49 ~ 185.56 oC( 77.87 ~ 366.01 oF)'
' 26.08 ~ 30.63 oC( 78.94 ~ 87.14 oF)'
' -5.31 ~ 1.00 J/cm2-sec( -0.03 ~ 0.01 Btu/in2-sec)'
' -56.74 ~ 10.70 J/cm2( -0.35 ~ 0.07 Btu/in2)'
' 0.12 ~ 2.10 J/cm2-sec( 0.00 ~ 0.01 Btu/in2-sec)'
' 1.27 ~ 22.49 J/cm2( 0.01 ~ 0.14 Btu/in2)'
2 comentarios
Rik
el 3 de Nov. de 2020
What did you try already? It helps if you try to come up with the complete list of patterns that the numbers can have. That way you can see if textscan will suffice, or if you need a regular expression (or the new pattern functionality).
Respuesta aceptada
dpb
el 3 de Nov. de 2020
Presuming from the above you have the cellstr array given, using the simplified string-matching functions, one solution would be something like:
% make a cellstr array from the text...
c={' 0.78 sec'
' 47.08 oC(116.75 oF)'
' 27.84 oC( 82.10 oF)'
' -0.83 J/cm2-sec (-5.07e-03 Btu/in2-sec)'
' -8.86 J/cm2 (-5.42e-02 Btu/in2)'
' 0.44 J/cm2-sec (2.70e-03 Kbtu/in2-sec)'
' 4.71 J/cm2 (2.89e-02 Btu/in2)'
' 25.49 ~ 185.56 oC( 77.87 ~ 366.01 oF)'
' 26.08 ~ 30.63 oC( 78.94 ~ 87.14 oF)'
' -5.31 ~ 1.00 J/cm2-sec( -0.03 ~ 0.01 Btu/in2-sec)'
' -56.74 ~ 10.70 J/cm2( -0.35 ~ 0.07 Btu/in2)'
' 0.12 ~ 2.10 J/cm2-sec( 0.00 ~ 0.01 Btu/in2-sec)'
' 1.27 ~ 22.49 J/cm2( 0.01 ~ 0.14 Btu/in2)'};
% the quotes are probably not really there but display of cell string, but just in case
% and because were in the pasted text to build the array, get rid of them...
c=strrep(c,"'",'');
% extract the first set numeric data
>> data=str2double(extractBefore(strtrim(c),' '))
data =
0.78
47.08
27.84
-0.83
-8.86
0.44
4.71
25.49
26.08
-5.31
-56.74
0.12
1.27
>>
strtrim removes the leading blanks so can use extractBefore on the blank in the record.
As Rik says, textscan would also work but it's often simpler to use other text processing. regexp is powerful but not needed for the basic problem posed.
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!