Home > NoiseTools > nt_iplot.m

# nt_iplot

## PURPOSE

[hh,ii]=nt_iplot(fname) - plot data file based on index

## SYNOPSIS

function [hh,ii]=nt_iplot(name)

## DESCRIPTION

    [hh,ii]=nt_iplot(fname) - plot data file based on index

      hh, ii: header info and index

      name: file name

      nt_iplot(name): just plot the data, mean removed

     See nt_index.

     NoiseTools

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_demean [y,mn]=nt_demean(x,w) - remove weighted mean over cols
- nt_greetings nt_greetings - display message the first time the toolbox is used
- nt_index [status,p]=nt_index(name,p,forceUpdate) - index data files & directories

This function is called by:

## SOURCE CODE

    0001 function [hh,ii]=nt_iplot(name)
    0002 %[hh,ii]=nt_iplot(fname) - plot data file based on index
    0003 %
    0004 %  hh, ii: header info and index
    0005 %
    0006 %  name: file name
    0007 %
    0008 %  nt_iplot(name): just plot the data, mean removed
    0009 %
    0010 % See nt_index.
    0011 %
    0012 % NoiseTools
    0013 nt_greetings;
    0014
    0015 if nargin<1 || isempty(name);
    0016     error('!');
    0017 end
    0018
    0019 % check 'name'
    0020 if ~ischar(name); error('name should be a string'); end
    0021 avoid=['[',1:31, 127,']'];
    0022 if regexp(name,avoid);
    0023     disp('bad character in file name, skip:'); disp(['   >',name,'<']);
    0024     return;
    0025 end
    0026 if name=='.'; name=pwd; end
    0027 if name(end)=='/'; name=name(1:end-1); end % remove trailing slash
    0028 [PATHSTR,NAME,EXT]=fileparts(name);
    0029 if strcmp(EXT,'idx');
    0030     disp(['warning: ', name, ' might be index file']);
    0031 end
    0032 if isempty(PATHSTR); % interpret relative to current directory
    0033     name=[pwd,filesep,name]; % full path, safe to use 'exist'
    0034 end
    0035 [PATHSTR,NAME,EXT]=fileparts(name);
    0036 if 2==exist(name)
    0037     d=dir(name);
    0038     filename=d.name;            % match case to file system
    0039     PATHSTR=cd(cd(PATHSTR));    % match case to file system
    0040     name=[PATHSTR,filesep,filename];
    0041 elseif 7==exist(name)
    0042     name=cd(cd(name));          % match case to file system
    0043     [PATHSTR,NAME,EXT]=fileparts(name);
    0044 else
    0045     error('...is neither file nor directory');
    0046 end
    0047
    0048 if 2~=exist(name)  &&  ~strcmp('.ds',EXT);
    0049     disp('can only handle files');
    0050     disp(['  >',name,'<']);
    0051 end
    0052
    0053 % index directory
    0054 idxDir=[PATHSTR,filesep,'nt_idx'];
    0055 if 7 ~= exist(idxDir);
    0056     nt_index(name);
    0057 end
    0058
    0059 % index file
    0060 idxName=[idxDir,filesep,NAME,EXT,'.idx'];
    0061 hhh.idxName=idxName;
    0062 if ~2==exist(idxName);
    0063     nt_index(name);
    0064 end
    0065
    0066 load ('-mat',idxName);  % loads hh, ii
    0067
    0068 %figure(1); clf
    0069 t=0:size(ii.min,1)-1;
    0070 if ~isempty(hh.sr) && isfield (ii,'scale');
    0071     t=t*ii.scale/hh.sr;
    0072     xlab=['seconds (',num2str(ii.nsamples),' samples)'];
    0073 else
    0074     xlab='samples';
    0075 end
    0076 plot(t,nt_demean([ii.min,ii.max]));
    0077 xlabel(xlab);
    0078 xlim([t(1) t(end)]);
    0079 title(NAME,'interpreter','none');
    0080
    0081 if ~nargout
    0082     hh=[];ii=[];
    0083 end
    0084