|
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
|