SELECT SPECIFIC VALUES FROM AN ARRAY

5 views (last 30 days)
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 Comments
Rik
Rik on 3 Nov 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).
Juan Pablo Guamn Bernal
Juan Pablo Guamn Bernal on 9 Nov 2020
Thanks for your time, yeah I tried textscan but the outcome was hard to organize

Sign in to comment.

Accepted Answer

dpb
dpb on 3 Nov 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.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!