1 ## Copyright (C) 2008 Bill Denney <bill@denney.ws>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {[@var{data}, @var{varnames}, @var{casenames}] =} tblread (@var{filename})
18 ## @deftypefnx {Function File} {[@var{data}, @var{varnames}, @var{casenames}] =} tblread (@var{filename}, @var{delimeter})
19 ## Read tabular data from an ascii file.
21 ## @var{data} is read from an ascii data file named @var{filename} with
22 ## an optional @var{delimeter}. The delimeter may be any single
25 ## @item "space" " " (default)
32 ## The @var{data} is read starting at cell (2,2) where the
33 ## @var{varnames} form a char matrix from the first row (starting at
34 ## (1,2)) vertically concatenated, and the @var{casenames} form a char
35 ## matrix read from the first column (starting at (2,1)) vertically
37 ## @seealso{tblwrite, csv2cell, cell2csv}
40 function [data, varnames, casenames] = tblread (f="", d=" ")
43 if nargin < 1 || nargin > 2
47 ## FIXME: open a file dialog box in this case when a file dialog box
49 error ("tblread: filename must be given")
51 [d err] = tbl_delim (d);
53 error ("tblread: %s", err)
57 data = cell2mat (d(2:end, 2:end));
58 varnames = strvcat (d(1,2:end));
59 casenames = strvcat (d(2:end,1));
69 %! [dt vt ct] = tblread ("tblread-space.dat");
74 %! [dt vt ct] = tblread ("tblread-space.dat", " ");
79 %! [dt vt ct] = tblread ("tblread-space.dat", "space");
84 %! [dt vt ct] = tblread ("tblread-tab.dat", "tab");
89 %! [dt vt ct] = tblread ("tblread-tab.dat", "\t");
94 %! [dt vt ct] = tblread ("tblread-tab.dat", '\t');