Got Questions? Get Answers.
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:
Reading specific lines (with some frequency) with textscan

Subject: Reading specific lines (with some frequency) with textscan

From: Negin Nazarian

Date: 30 Jun, 2013 21:59:09

Message: 1 of 2

Hello all,

I have an ascii file that I need to process. It is in this format:
"
 "Surface Integral Report"

           Area-Weighted Average
             Radiation Heat Flux (w/m2)
-------------------------------- --------------------
                            wall 34.189476
                         wall_aw 28.288052
                ---------------- --------------------
                             Net 34.208313

           Area-Weighted Average
             Radiation Heat Flux (w/m2)
-------------------------------- --------------------
                            wall 34.324566
                         wall_aw 28.363642
                ---------------- --------------------
                             Net 34.345776
"
and the file has more than 1000 of this sets but all I need is the "Net" values. How can I use textscan in a way that reads the file and only make an array of Net values?

Any help is appreciated.
Cheers,
Negin

Subject: Reading specific lines (with some frequency) with textscan

From: TideMan

Date: 30 Jun, 2013 22:21:42

Message: 2 of 2

On Monday, July 1, 2013 9:59:09 AM UTC+12, Negin Nazarian wrote:
> Hello all,
>
>
>
> I have an ascii file that I need to process. It is in this format:
>
> "
>
> "Surface Integral Report"
>
>
>
> Area-Weighted Average
>
> Radiation Heat Flux (w/m2)
>
> -------------------------------- --------------------
>
> wall 34.189476
>
> wall_aw 28.288052
>
> ---------------- --------------------
>
> Net 34.208313
>
>
>
> Area-Weighted Average
>
> Radiation Heat Flux (w/m2)
>
> -------------------------------- --------------------
>
> wall 34.324566
>
> wall_aw 28.363642
>
> ---------------- --------------------
>
> Net 34.345776
>
> "
>
> and the file has more than 1000 of this sets but all I need is the "Net" values. How can I use textscan in a way that reads the file and only make an array of Net values?
>
>
>
> Any help is appreciated.
>
> Cheers,
>
> Negin

One way is to read all the lines in as strings:
c=textscan(fid,'%s');
then to look for the lines with Net in them:
indx=strmatch('Net',c{1});
and process those to extract the numbers using str2num

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