Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
extracting numbers from text string

Subject: extracting numbers from text string

From: Fran

Date: 18 May, 2012 07:27:25

Message: 1 of 3

Hello,

I am new to Matlab. I have a very long text file with a repeating structure like:

-----

Courant Number mean: 0 max: 0.136
Iteration No 1
DILUPBiCG: Solving for Ux, Initial residual = 1, Final residual = 2.99476e-08, No Iterations 2
DILUPBiCG: Solving for Uy, Initial residual = 0, Final residual = 0, No Iterations 0
DICPCG: Solving for p, Initial residual = 1, Final residual = 9.41218e-08, No Iterations 737
time step continuity errors : sum local = 7.34978e-12, global = -2.46208e-14, cumulative = -2.46208e-14
DICPCG: Solving for p, Initial residual = 3.59809e-05, Final residual = 9.55252e-08, No Iterations 604
time step continuity errors : sum local = 1.37508e-08, global = -2.92546e-11, cumulative = -2.92792e-11
DICPCG: Solving for p, Initial residual = 4.44746e-07, Final residual = 9.49638e-08, No Iterations 4
time step continuity errors : sum local = 1.29697e-08, global = 1.91066e-10, cumulative = 1.61787e-10
DICPCG: Solving for PotE, Initial residual = 0, Final residual = 0, No Iterations 0
Iteration No 2
DILUPBiCG: Solving for Ux, Initial residual = 0.00227304, Final residual = 1.46529e-07, No Iterations 2
DILUPBiCG: Solving for Uy, Initial residual = 0.00270324, Final residual = 2.49839e-07, No Iterations 2
DICPCG: Solving for p, Initial residual = 0.000117855, Final residual = 9.99383e-08, No Iterations 451
time step continuity errors : sum local = 1.32192e-08, global = -1.70539e-09, cumulative = -1.5436e-09
DICPCG: Solving for p, Initial residual = 1.19641e-05, Final residual = 9.84828e-08, No Iterations 400
time step continuity errors : sum local = 1.30281e-08, global = 1.83845e-11, cumulative = -1.52522e-09
DICPCG: Solving for p, Initial residual = 1.42252e-06, Final residual = 8.98636e-08, No Iterations 4
time step continuity errors : sum local = 1.1888e-08, global = 1.05161e-10, cumulative = -1.42006e-09
DICPCG: Solving for PotE, Initial residual = 0, Final residual = 0, No Iterations 0
Iteration No 3
DILUPBiCG: Solving for Ux, Initial residual = 1.68533e-05, Final residual = 4.37189e-07, No Iterations 1
DILUPBiCG: Solving for Uy, Initial residual = 2.16801e-05, Final residual = 5.83916e-07, No Iterations 1
DICPCG: Solving for p, Initial residual = 1.83766e-06, Final residual = 8.53894e-08, No Iterations 10
time step continuity errors : sum local = 1.12961e-08, global = 7.52266e-11, cumulative = -1.34483e-09
DICPCG: Solving for p, Initial residual = 2.3926e-07, Final residual = 9.16602e-08, No Iterations 1
time step continuity errors : sum local = 1.21256e-08, global = 7.26966e-11, cumulative = -1.27213e-09
DICPCG: Solving for p, Initial residual = 9.89624e-08, Final residual = 9.89624e-08, No Iterations 0
time step continuity errors : sum local = 1.30916e-08, global = 7.25284e-11, cumulative = -1.19961e-09
DICPCG: Solving for PotE, Initial residual = 0, Final residual = 0, No Iterations 0
ExecutionTime = 4.13 s ClockTime = 4 s

-----


I would like to be able to scan the text file and select the numbers that are related to a certain quantity, i.e. "Ux, Initial Residual = "

How does one do this?

Thank you,

Francesco

Subject: extracting numbers from text string

From: Bruno Luong

Date: 18 May, 2012 07:43:17

Message: 2 of 3

You can use textscan() command to read the file, then regexp() to extract substrings, then str2double() to convert to numbers.

Bruno

Subject: extracting numbers from text string

From: Fran

Date: 18 May, 2012 09:25:07

Message: 3 of 3

Hello,

I did

fid = fopen('text.txt')

but I am confused as to what I should use in 'FORMAT' in the textscan command.

Thank you,

F

"Bruno Luong" <brunoluong@yahoo.com> wrote in message <jp4uil$h7t$1@newscl01ah.mathworks.com>...
> You can use textscan() command to read the file, then regexp() to extract substrings, then str2double() to convert to numbers.
>
> Bruno

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us