[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: help with octave
From: |
niles |
Subject: |
Re: help with octave |
Date: |
Wed, 28 Jun 95 07:29:27 -0400 |
> Can anyone please show me how to use "fscanf" with an example??
This function will read "flat" ascii. Space/Tab delimit columns,
CR/NL delimit rows. REALLY slow for big files.
Rick Niles.
% Function to read in time history file without titles.
% function data = loadth(title, header, ncols, nrows)
function data = loadth(title, header, ncols, nrows)
fp = fopen(title, "r");
fseek(fp, 0, SEEK_END);
eof = ftell(fp);
frewind(fp);
if (header)
headeris =1
for col=1:ncols
name = fscanf(fp, "%s")
endfor
endif
if (~exist('nrows'))
eoh = ftell(fp);
pos = 0;
nrows = 1;
while( pos < eof-4 )
for col=1:ncols
a = fscanf(fp, "%lf");
endfor
nrows++;
pos = ftell(fp);
endwhile
nrows
fseek(fp, eoh, SEEK_SET);
endif
data = zeros(nrows,ncols);
pos = 0;
row = 1;
for row=1:nrows
for col=1:ncols
data(row,col) = fscanf(fp, "%lf");
endfor
endfor
endfunction