help-octave
[Top][All Lists]
Advanced

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

Re: importdata


From: mallet
Subject: Re: importdata
Date: Thu, 22 Apr 2010 00:48:01 -0800 (PST)

In fact, i just have to change the behavior of dmread to not fill blank to
zero but to NaN ?
This can be done by using <math.h> : 
http://www.gnu.org/s/libc/manual/html_node/Infinity-and-NaN.html
http://www.gnu.org/s/libc/manual/html_node/Infinity-and-NaN.html .

But i tried «mkoctfile dlmread.cc» without any changes and i got several
errors. It seems i’m not abble to compile files from DLD-FUNCTIONS
directory.

What’s the matter?


mallet wrote:
> 
> Hi,
> I want to import a file like this one in the way of «importdata» from
> Matlab:
> 
> A ;B ;C
> 1 ;2 ;3
> 4 ;5 ;
> 
> so i wrote the function below (some parts are from Matlab).
> There’ s the snag: some values are missing in files and the way i found
> (using dlmread) replace it by 0. Or in the Matlab it would be replaced by
> NaN. I tryed using textread with option «'emptyvalue', NaN»
> but it neither do work .
> 
> 
> function [out, delimiter, headerlines] = importdata(varargin)
> 
>       FileName = varargin{1};
> 
>       % Recupere les infos d'entree:
>       if nargin > 1
>               delimRequested = varargin{2};
>       else
>               delimRequested = NaN;
>       end
> 
>       if nargin > 2
>               headerlines = varargin{3};
>       else
>               headerlines = 1;
>       end
> 
>       if nargin > 3
>               disp('Too many input');
>               return;
>       end
> 
>       delimiter      = fct_delimiter(FileName,delimRequested);
> 
>       out.data       = dlmread(FileName,delimiter,headerlines,0);
> 
>       fid            = fopen(FileName);
>       string         = fgetl(fid);
>       fclose(fid);
> 
>       out.colheaders = strsplit(string,delimiter);
> 
>       % Fin importdata
> 
> function delimiter = fct_delimiter(FileName,delimRequested)
>       % Defini le delimiteur 
>       if isnan(delimRequested)
>               fid = fopen(FileName);
>               str = fread(fid, 4096,'*char')';
>               fclose(fid);
>               delimPrinted = guessdelim(str);%%mfile from matlab
>               delimRequested = delimPrinted;
> 
>       else
>               delimPrinted = sprintf(delimRequested);
>       end
>       delimiter = delimPrinted;
> 

-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/importdata-tp2019104p2020240.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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