Thread Subject:
textscan

Subject: textscan

From: Dave Brackett

Date: 20 Jan, 2010 15:21:20

Message: 1 of 1

Hi, i have some data in a file which I want to parse.
A sample of the data is:
 1 56 0 2 0 0 0 0 0
  3.187053528E+2 3.308506165E+2 1.847287445E+2
1G 6 0 0 000000
 1 57 0 2 0 0 0 0 0
  3.186506958E+2 3.309122314E+2 1.856408844E+2
1G 6 0 0 000000
 1 181252 0 2 0 0 0 0 0
  3.186141357E+2 3.304845276E+2 1.854063416E+2
1G 6 0 0 000000
 1 181253 0 2 0 0 0 0 0
  3.192148438E+2 3.309580994E+2 1.863746490E+2
1G 6 0 0 000000


Ideally I would like to read in just column 2 on rows 5:3:end, and columns 1:3 on rows 6:3:end.

The code below is what I have at the moment. I would prefer to read each value in using textscan but can't seem to get that to work. So currently I'm using sscanf to split up each string from the text file but this is very slow as node_out.txt has ~200,000 rows. Can anyone help me with this please? Thanks.


fid=fopen('U:\node_out.txt');
node_raw=textscan(fid,'%s','Delimiter','\n');
fclose(fid)

id_inc=1;
coord_inc=1;

% preallocation
node_id=zeros(67435,9);
node_coords=zeros(67435,3);

for i=5:3:size(node_raw{1},1)
    node_id(i,:)=sscanf(node_raw{1}{i},'%d')';
    id_inc=id_inc+1;
end

for i=6:3:size(node_raw{1},1)
    node_coords(i,:)=sscanf(node_raw{1}{i},'%f')';
    coord_inc=coord_inc+1;
end

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
textread Dave B 20 Jan, 2010 10:24:05
sscanf Dave B 20 Jan, 2010 10:24:05
rssFeed for this Thread

Contact us