octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: More octave-forge functions!!!


From: David Bateman
Subject: Re: More octave-forge functions!!!
Date: Mon, 29 May 2006 22:46:11 +0200
User-agent: Mozilla Thunderbird 1.0.6-7.6.20060mdk (X11/20050322)

Alois Schloegl wrote:
> 
> STR2DOUBLE should be very useful for implementing CSVREAD and DLMREAD
> 
> function m = cvsread(filename)
>    fid =fopen(filename,'r');
>    s= char(fread(fid,inf,'char'));
>    fclose(s);
>    m = str2double(s);
> endfunction

That's cute, though it should be "fclose(fid)", and fread should be
transposed. For complete compatiability shoudn't the delimiters also be
defined, since ";" is not considered a row delimiter. That is

function m = cvsread(filename, row)
  if (nargin < 1 || nargin > 2)
    print_usage();
  endif
  if (nargin < 2)
    row = 0;
  endif

  fid =fopen(filename,'r');
  s= char(fread(fid,inf,'char')');
  fclose(fid);
  nline = regexp(s,'\n');
  s = s(nline(row)
  m = str2double(s,',','\r\n');
endfunction

In a similar vain

function m = dlmread (filename, delim, row)
  if (nargin < 1 || nargin > 3)
    print_usage();
  endif
  if (nargin < 3)
    row = 0;
  endif
  if (nargin < 2)
    delim = ',';
  endif

  fid = fopen(filename,'r');
  s = char (fread (fid, inf, 'char')');
  fclose (fid);
  nline = regexp(s,'\n');
  s = s(nline(row)
  m = str2double(s, delim, '\r\n');
endfunction

Though completely untested...

D.



> 
> 
> 
> Alois
> 
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]