Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Separate data from text in a txt file? or fetch the data in txt file
Replies: 1   Last Post: Apr 6, 2013 10:23 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,250
Registered: 6/7/07
Re: Separate data from text in a txt file? or fetch the data in
txt file

Posted: Apr 6, 2013 10:23 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 4/6/2013 7:41 AM, fatih23 wrote:
...

> I have a txt file as in the below. And what i am trying to do is to be
> able to fetch my data and plot them. i have been using 'fscanf' but i
> wasn't able succeed. i was wondering if anyone knows an easy way to
> separate data from a txt or dat file, so that i can use just the 'load'
> function to process my data?
>
>
> Field Output reported at nodes for part: PART-1-1
> Computation algorithm: EXTRAPOLATE_COMPUTE_AVERAGE
> Averaged at nodes
> Averaging regions: ODB_REGIONS
>
> Node U.U2 S max S.S11
> Label @Loc 1 @Loc 1 @Loc 1
> -----------------------------------------------------------------
> 1 -508.707E-03 3.55079E-03 -1.19326
> 2 -460.343E-03 197.177E-03 -1.09810
> 3 -460.343E-03 197.177E-03 -1.09810
> 4 -508.707E-03 3.55079E-03 -1.19326
> 5 -458.758E-03 818.933E-03 793.610E-03
> 6 -458.758E-03 818.933E-03 793.610E-03
> 7 -504.776E-03 862.675E-03 842.660E-03
> 8 -504.776E-03 862.674E-03 842.660E-03
> 9 111.270E-03 48.0522E-03 48.0480E-03
> 10 -318.989E-03 4.07685E-03 2.47891E-03
> 11 135.668E-03 4.23023E-03 -1.19628E-03
> 12 -319.035E-03 612.056E-06 -1.81646E-03
> 13 135.686E-03 663.212E-06 603.243E-06
> 14 111.297E-03 -120.055E-06 -67.4964E-03
> 15 111.297E-03 -120.055E-06 -67.4964E


Piece o' cake w/ that...

In a single array...

>> type fatih.dat

Field Output reported at nodes for part: PART-1-1
Computation algorithm: EXTRAPOLATE_COMPUTE_AVERAGE
Averaged at nodes
Averaging regions: ODB_REGIONS

Node U.U2 S max S.S11
Label @Loc 1 @Loc 1 @Loc 1
-----------------------------------------------------------------
1 -508.707E-03 3.55079E-03 -1.19326
2 -460.343E-03 197.177E-03 -1.09810
...
14 111.297E-03 -120.055E-06 -67.4964E-03
15 111.297E-03 -120.055E-06 -67.4964E

>> x=textread('fatih.dat','%f','headerlines',8);
>> x=reshape(x,4,[])'

x =
1.0000 -0.5087 0.0036 -1.1933
2.0000 -0.4603 0.1972 -1.0981
...
15.0000 0.1113 -0.0001 -67.4964
>>

As separate variables, use a file-specific format string...

[n,x,y,z]=textread('fatih.dat',repmat('%f',1,4),'headerlines',8);

New-fangled to get as cell array, use textscan() instead of textread()

doc textread
doc textscan

There's also the import tool...

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.