Home > wafo > misc > loaddata.m

loaddata

PURPOSE ^

Loads a matrix from a text file.

SYNOPSIS ^

data=loaddata(filename)

DESCRIPTION ^

  LOADDATA Loads a matrix from a text file.
           
   CALL: data=loaddata(filename)
 
         data     = the output data matrix.
         filename = a string containing the file to read.
 
   This routine is used to allow m-functions to load data files
   with their own name. ("fun.m" can't use "load fun.dat;v=fun;", but 
   can use "v=loaddata('fun.dat');")
  Example:% 
 
  x=loaddata('sea.dat'); size(x)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function data=loaddata(filename)
002 % LOADDATA Loads a matrix from a text file.
003 %          
004 %  CALL: data=loaddata(filename)
005 %
006 %        data     = the output data matrix.
007 %        filename = a string containing the file to read.
008 %
009 %  This routine is used to allow m-functions to load data files
010 %  with their own name. ("fun.m" can't use "load fun.dat;v=fun;", but 
011 %  can use "v=loaddata('fun.dat');")
012 % Example:% 
013 %
014 % x=loaddata('sea.dat'); size(x)
015 
016 varname=filename;
017 i=findstr(varname,'.');
018 if ~isempty(i)
019   varname=varname(1:max(i)-1);
020 end
021 i=findstr(varname,'\'); % PC systems
022 if ~isempty(i)
023   varname=varname(max(i)+1:length(varname));
024 end
025 i=findstr(varname,'/'); % Unix systems
026 if ~isempty(i)
027   varname=varname(max(i)+1:length(varname));
028 end
029 
030 load(filename,'-ascii');
031 eval(['data=' varname ';']);
032 eval(['clear ' varname]);
033

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003