annotate rDiff/src/octave/importdata.m @ 2:233c30f91d66

updated python based GFF parsing module which will handle GTF/GFF/GFF3 file types
author vipints <vipin@cbio.mskcc.org>
date Tue, 08 Oct 2013 07:15:44 -0400
parents 0f80a5141704
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
1 ## Copyright (C) 2012 Erik Kjellson
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
2 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
3 ## This file is part of Octave.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
4 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
8 ## your option) any later version.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
9 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
13 ## General Public License for more details.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
14 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
17 ## <http://www.gnu.org/licenses/>.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
18
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
19 ## -*- texinfo -*-
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
20 ## @deftypefn {Function File} {@var{A} =} importdata (@var{fname})
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
21 ## @deftypefnx {Function File} {@var{A} =} importdata (@var{fname}, @var{delimiter})
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
22 ## @deftypefnx {Function File} {@var{A} =} importdata (@var{fname}, @var{delimiter}, @var{header_rows})
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
23 ## @deftypefnx {Function File} {[@var{A}, @var{delimiter}] =} importdata (...)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
24 ## @deftypefnx {Function File} {[@var{A}, @var{delimiter}, @var{header_rows}] =} importdata (...)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
25 ## Importing data from file.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
26 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
27 ## Importing the contents of file @var{fname} into workspace.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
28 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
29 ## Input parameters:
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
30 ## @itemize
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
31 ## @item @var{fname}
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
32 ## The file name for the file to import.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
33 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
34 ## @item @var{delimiter}
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
35 ## The character separating columns of data. Use @code{\t} for tab.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
36 ## (Only valid for ascii files)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
37 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
38 ## @item @var{header_rows}
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
39 ## Number of header rows before the data begins. (Only valid for ascii files)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
40 ## @end itemize
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
41 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
42 ## Different file types are supported:
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
43 ## @itemize
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
44 ## @item Ascii table
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
45 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
46 ## Importing ascii table using the specified number of header rows and
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
47 ## the specified delimiter.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
48 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
49 ## @item Image file
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
50 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
51 ## @item @sc{Matlab} file
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
52 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
53 ## @item Spreadsheet files (depending on external software)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
54 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
55 ## @item Wav file
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
56 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
57 ## @end itemize
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
58 ##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
59 ## @seealso{textscan, dlmread, csvread, load}
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
60 ## @end deftypefn
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
61
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
62 ## Author: Erik Kjellson <erikiiofph7@users.sourceforge.net>
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
63
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
64 function [output, delimiter, header_rows] = importdata (varargin)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
65
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
66
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
67 ## Default values
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
68 fname = "";
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
69 delimiter = "";
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
70 header_rows = -1;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
71
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
72 ##########
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
73
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
74 ## Check input arguments
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
75
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
76 if (nargin < 1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
77 print_usage ();
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
78 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
79
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
80 fname = varargin{1};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
81 ## Check that the file name really is a string
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
82 if (! ischar (fname))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
83 error ("importdata: file name needs to be a string");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
84 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
85 if ( strcmpi (fname, "-pastespecial"))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
86 error ("importdata: option -pastespecial not implemented");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
87 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
88
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
89 if (nargin > 1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
90 delimiter = varargin{2};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
91 ## Check that the delimiter really is a string
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
92 if (!ischar (delimiter))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
93 error("importdata: delimiter needs to be a character");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
94 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
95 if (length (delimiter) > 1 && !strcmpi (delimiter, "\\t"))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
96 error("importdata: delimiter cannot be longer than 1 character");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
97 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
98 if (strcmpi (delimiter, "\\"))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
99 delimiter = "\\\\";
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
100 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
101 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
102
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
103 if (nargin > 2)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
104 header_rows = varargin{3};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
105 if (!isnumeric (header_rows) || header_rows < 0)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
106 error ("importdata: number of header rows needs to be an integer number >= 0");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
107 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
108 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
109
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
110 if (nargin > 3)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
111 error ("importdata: too many input arguments");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
112 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
113
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
114 ##########
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
115
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
116 ## Check file format
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
117 ## Get the extension from the file name.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
118 [d n fileExt v] = fileparts (fname);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
119 ## Make sure file extension is in lower case.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
120 fileExt = lower (fileExt);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
121
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
122 switch fileExt
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
123 case {".au", ".snd"}
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
124 error (sprintf ("importdata: not implemented for file format %s",
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
125 fileExt));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
126 case ".avi"
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
127 error (sprintf ("importdata: not implemented for file format %s",
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
128 fileExt));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
129 case {".bmp", ".cur", ".gif", ".hdf", ".ico", ".jpe", ".jpeg", ".jpg", \
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
130 ".pbm", ".pcx", ".pgm", ".png", ".pnm", ".ppm", ".ras", \
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
131 ".tif", ".tiff", ".xwd"}
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
132 delimiter = NaN;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
133 header_rows = 0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
134 [output.cdata, output.colormap, output.alpha] = imread (fname);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
135 case ".mat"
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
136 delimiter = NaN;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
137 header_rows = 0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
138 output = load (fname);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
139 case {".wk1", ".xls", ".xlsx", ".dbf", ".pxl"}
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
140 ## If there's no Excel file support simply fall back to unimplemented.m
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
141 output = xlsread (fname);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
142 case {".ods", ".sxc", ".fods", ".uos", ".xml"}
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
143 ## unimplemented.m only knows ML functions; odsread isn't one but is in OF
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
144 try
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
145 output = odsread (fname);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
146 catch
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
147 ## Fall back to unimplemented.m.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
148 output = xlsread (fname);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
149 end_try_catch
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
150 case {".wav", ".wave"}
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
151 delimiter = NaN;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
152 header_rows = 0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
153 [output.data, output.fs] = wavread (fname);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
154 otherwise
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
155 ## Assume the file is in ascii format.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
156 [output, delimiter, header_rows] = \
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
157 importdata_ascii (fname, delimiter, header_rows);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
158 endswitch
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
159
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
160 ## If there are any empty fields in the output structure, then remove them
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
161 if (isstruct (output) && length (output) == 1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
162 fields = fieldnames (output);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
163 for i=1:length (fields)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
164 if (isempty (getfield (output, fields{i})))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
165 output = rmfield (output, fields{i});
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
166 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
167 endfor
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
168
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
169 ## If only one field is left, replace the structure with the field,
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
170 ## i.e. output = output.onlyFieldLeft
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
171
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
172 ## Update the list of fields
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
173 fields = fieldnames (output);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
174 if (length (fields) == 1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
175 output = getfield (output, fields{1});
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
176 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
177 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
178 endfunction
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
179
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
180
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
181 ########################################
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
182
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
183 function [output, delimiter, header_rows] = \
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
184 importdata_ascii (fname, delimiter, header_rows)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
185
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
186 ## Define the fields in the output structure so that the order will be
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
187 ## correct.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
188
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
189 output.data = [];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
190 output.textdata = [];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
191 output.rowheaders = [];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
192 output.colheaders = [];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
193
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
194 ## Read file into string and count the number of header rows
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
195 #file_content = fileread (fname);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
196 file_content_rows={};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
197 fid=fopen(fname);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
198 currline=0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
199 firstline=1;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
200 while 1==1
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
201 if not(isempty(currline))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
202 if currline==-1
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
203 break
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
204 end
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
205 end
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
206 currline=fgetl(fid);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
207 file_content_rows{end+1}=currline;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
208 end
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
209 fclose(fid);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
210 file_content_rows={file_content_rows{1:(end-1)}};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
211
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
212 ## Split the file into rows (using \r\n or \n as delimiters between rows).
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
213 #file_content_rows = regexp (file_content, "\r?\n", "split");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
214
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
215 ## FIXME: guess delimiter, if it isn't defined
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
216 if (isempty (delimiter))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
217 error ("importdata: Guessing delimiter is not implemented yet, you have to specify it.");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
218 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
219
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
220 ## FIXME: A more intelligent way to count number of header rows. This
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
221 ## is needed e.g. when delimiter=' ' and the header contains spaces...
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
222
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
223 ## If number of header rows is undefined, then count the number of
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
224 ## header rows by step through row by row and look for the delimiter.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
225 ## Assume that the header can't contain any delimiter.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
226 if (header_rows < 0)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
227 header_rows = 0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
228 for i=1:length (file_content_rows)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
229 if (isempty (regexp(file_content_rows{i}, delimiter, "once")))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
230 header_rows++;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
231 else
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
232 ## Data part has begun and therefore no more header rows can be
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
233 ## found
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
234 break;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
235 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
236 endfor
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
237 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
238
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
239 ## Put the header rows in output.textdata.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
240 if (header_rows > 0)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
241 output.textdata = file_content_rows (1:header_rows)';
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
242 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
243
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
244 ## If space is the delimiter, then remove spaces in the beginning of
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
245 ## each data row.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
246 if (strcmpi (delimiter, " "))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
247 for i=(header_rows+1):length (file_content_rows)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
248 ## strtrim does not only remove the leading spaces but also the
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
249 ## tailing spaces, but that doesn't really matter.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
250 file_content_rows{i} = strtrim (file_content_rows{i});
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
251 endfor
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
252 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
253
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
254 ## Remove empty data rows. Go through them backwards so that you wont
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
255 ## get out of bounds.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
256 for i=length (file_content_rows):-1:(header_rows + 1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
257 if (length (file_content_rows{i}) < 1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
258 file_content_rows = [file_content_rows(1:i-1), \
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
259 file_content_rows(i+1:length(file_content_rows))];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
260 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
261 endfor
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
262
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
263 ## Count the number of data columns. If there are different number of
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
264 ## columns, use the greatest value.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
265 data_columns = 0;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
266 delimiter_pattern = delimiter;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
267 ## If space is the delimiter, then multiple spaces should count as ONE
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
268 ## delimiter. Also ignore leading spaces.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
269 if (strcmpi (delimiter, " "))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
270 delimiter_pattern = ' +';
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
271 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
272 for i=(header_rows+1):length(file_content_rows)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
273 data_columns = max (data_columns,
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
274 length (regexp (file_content_rows{i},
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
275 delimiter_pattern, "split")));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
276 endfor
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
277
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
278 ## Go through the data and put it in either output.data or
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
279 ## output.textdata depending on if it is numeric or not.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
280 output.data = NaN (length (file_content_rows) - header_rows, data_columns);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
281
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
282 cut_rows=zeros(1,data_columns);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
283 for i=(header_rows+1):length(file_content_rows)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
284 ## Only use the row if it contains anything other than white-space
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
285 ## characters.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
286 if (any (file_content_rows{i} != " "))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
287 row_data = regexp (file_content_rows{i}, delimiter_pattern, "split");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
288
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
289 for j=1:length(row_data)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
290 ## Try to convert the column to a number, if it works put it in
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
291 ## output.data, otherwise in output.textdata
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
292 if (!isempty (row_data{j}))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
293 data_numeric = str2double (row_data{j});
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
294 if and(!isempty (data_numeric),not(isnan(data_numeric)))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
295 output.data(i-header_rows, j) = data_numeric;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
296 if not(isnan(data_numeric))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
297 cut_rows(j)=1;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
298 end
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
299 else
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
300 output.textdata{i,j} = row_data{j};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
301 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
302 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
303 endfor
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
304
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
305 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
306 endfor
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
307 output.data=output.data(:,cut_rows>0);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
308
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
309 ## Check wether rowheaders or colheaders should be used
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
310 if ((header_rows == data_columns) && (size (output.textdata, 2) == 1))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
311 output.rowheaders = output.textdata;
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
312 elseif (size (output.textdata, 2) == data_columns)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
313 output.colheaders = output.textdata(end,:);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
314 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
315
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
316 ## When delimiter = "\\t" convert it to a tab, done for Matlab compatibility.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
317 if (strcmp (delimiter, '\t'))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
318 delimiter = "\t";
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
319 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
320
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
321 endfunction
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
322
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
323
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
324 function [RET]=regexp(ARG1,ARG2,ARG3)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
325 %ARG3 is always 'split' in this context
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
326 if (strcmp (ARG2, '\t'))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
327 ARG2 = "\t";
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
328 endif
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
329 RET = strsplit(ARG1,"\t",fixed=true);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
330 endfunction
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
331
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
332 ########################################
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
333
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
334 %!test
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
335 %! # Comma separated values
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
336 %! A = [3.1 -7.2 0; 0.012 6.5 128];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
337 %! fn = tmpnam ();
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
338 %! fid = fopen (fn, "w");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
339 %! fputs (fid, "3.1,-7.2,0\n0.012,6.5,128");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
340 %! fclose (fid);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
341 %! [a,d,h] = importdata (fn, ",");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
342 %! unlink (fn);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
343 %! assert (a, A);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
344 %! assert (d, ",");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
345 %! assert (h, 0);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
346
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
347 %!test
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
348 %! # Tab separated values
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
349 %! A = [3.1 -7.2 0; 0.012 6.5 128];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
350 %! fn = tmpnam ();
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
351 %! fid = fopen (fn, "w");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
352 %! fputs (fid, "3.1\t-7.2\t0\n0.012\t6.5\t128");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
353 %! fclose (fid);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
354 %! [a,d,h] = importdata (fn, "\\t");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
355 %! unlink (fn);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
356 %! assert (a, A);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
357 %! assert (d, "\t");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
358 %! assert (h, 0);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
359
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
360 %!test
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
361 %! # Space separated values, using multiple spaces to align in columns.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
362 %! A = [3.1 -7.2 0; 0.012 6.5 128];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
363 %! fn = tmpnam ();
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
364 %! fid = fopen (fn, "w");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
365 %! fprintf (fid, "%10.3f %10.3f %10.3f\n", A(1,:));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
366 %! fprintf (fid, "%10.3f %10.3f %10.3f\n", A(2,:));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
367 %! fclose (fid);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
368 %! [a,d,h] = importdata (fn, " ");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
369 %! unlink (fn);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
370 %! assert (a, A);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
371 %! assert (d, " ");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
372 %! assert (h, 0);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
373
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
374 %!test
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
375 %! # Header
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
376 %! A.data = [3.1 -7.2 0; 0.012 6.5 128];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
377 %! A.textdata = {"This is a header row."; \
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
378 %! "this row does not contain any data, but the next one does."};
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
379 %! fn = tmpnam ();
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
380 %! fid = fopen (fn, "w");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
381 %! fputs (fid, [A.textdata{1} "\n"]);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
382 %! fputs (fid, [A.textdata{2} "\n"]);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
383 %! fputs (fid, "3.1\t-7.2\t0\n0.012\t6.5\t128");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
384 %! fclose (fid);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
385 %! [a,d,h] = importdata (fn, "\\t");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
386 %! unlink (fn);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
387 %! assert (a, A);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
388 %! assert (d, "\t");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
389 %! assert (h, 2);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
390
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
391 %!test
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
392 %! # Ignore empty rows containing only spaces
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
393 %! A = [3.1 -7.2 0; 0.012 6.5 128];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
394 %! fn = tmpnam ();
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
395 %! fid = fopen (fn, "w");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
396 %! fprintf (fid, "%10.3f %10.3f %10.3f\n", A(1,:));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
397 %! fputs (fid, " ");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
398 %! fprintf (fid, "%10.3f %10.3f %10.3f\n", A(2,:));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
399 %! fclose (fid);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
400 %! [a,d,h] = importdata (fn, " ");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
401 %! unlink (fn);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
402 %! assert (a, A);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
403 %! assert (d, " ");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
404 %! assert (h, 0);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
405
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
406 %!test
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
407 %! # Exponentials
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
408 %! A = [3.1 -7.2 0; 0.012 6.5 128];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
409 %! fn = tmpnam ();
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
410 %! fid = fopen (fn, "w");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
411 %! fputs (fid, "+3.1e0\t-72E-1\t0\n12e-3\t6.5\t128");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
412 %! fclose (fid);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
413 %! [a,d,h] = importdata (fn, "\\t");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
414 %! unlink (fn);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
415 %! assert (a, A);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
416 %! assert (d, "\t");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
417 %! assert (h, 0);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
418
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
419 %!test
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
420 %! # Missing values
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
421 %! A = [3.1 NaN 0; 0.012 6.5 128];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
422 %! fn = tmpnam ();
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
423 %! fid = fopen (fn, "w");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
424 %! fputs (fid, "3.1\t\t0\n0.012\t6.5\t128");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
425 %! fclose (fid);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
426 %! [a,d,h] = importdata (fn, "\\t");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
427 %! unlink (fn);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
428 %! assert (a, A);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
429 %! assert (d, "\t");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
430 %! assert (h, 0);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
431
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
432 %!test
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
433 %! # CRLF for line breaks
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
434 %! A = [3.1 -7.2 0; 0.012 6.5 128];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
435 %! fn = tmpnam ();
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
436 %! fid = fopen (fn, "w");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
437 %! fputs (fid, "3.1\t-7.2\t0\r\n0.012\t6.5\t128");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
438 %! fclose (fid);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
439 %! [a,d,h] = importdata (fn, "\\t");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
440 %! unlink (fn);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
441 %! assert (a, A);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
442 %! assert (d, "\t");
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
443 %! assert (h, 0);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
444