[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
reading text data with textscan annoyingly slow
From: |
MarcelK |
Subject: |
reading text data with textscan annoyingly slow |
Date: |
Wed, 2 Nov 2011 03:40:54 -0700 (PDT) |
http://octave.1599824.n4.nabble.com/file/n3972499/example1.ncf example1.ncf
Hi,
I'm using Octave 3.2.4. with Windows XP. (i686-pc-mingw32)
I'm also using GUIOctave 1.5.3. as frontend.
I'm facing some problems reading data from a .ncf text file.
I've attached an example of such a file (I hope that worked).
It takes about 60 seconds to read one single ncf file
However, in Matlab it takes not even a second.
Here's my code I use to read the data in:
function [Date1,headlines,nummatrix] = ncfread (filename)
fid=fopen(filename,'r');
%# read data headers
headerdata=fgets(fid);
index=findstr(headerdata,'}');
ncols=length(index);
headlines={};
headlines(1)=headerdata(1:index(1));
for mm=2:ncols
headlines(mm)=headerdata(index(mm-1)+1:index(mm));
endfor
textformat=['%s %s',repmat('%f',1,ncols-2)];
datacell=textscan(fid,textformat);
Date1=datacell{1,1}{1};
timedata=datacell{2};
fclose(fid);
%# generate time vector (time in hours)
t=zeros(size(datacell,1),1);
timestring=char(timedata);
for jj=1:size(timestring,1)
tstruct=strptime(timestring(jj,:),'%R');
t(jj)=tstruct.hour+tstruct.min/60;
endfor
%# conversion cell>matrix
nummatrix=zeros(length(datacell{1}),size(datacell,2));
nummatrix(:,2)=t;
for ii=3:size(nummatrix,2)
nummatrix(:,ii)=datacell{ii};
endfor
nummatrix(:,1)=[];
endfunction
My way of converting the "time string" (e.g. '10:00') to time in hours
(e.g. 10.00) seems quite complicated to me, is there maybe a better way to
achieve this?
Thanks in advance,
Marcel
--
View this message in context:
http://octave.1599824.n4.nabble.com/reading-text-data-with-textscan-annoyingly-slow-tp3972499p3972499.html
Sent from the Octave - General mailing list archive at Nabble.com.
- reading text data with textscan annoyingly slow,
MarcelK <=