From help-octave-request at bevo dot che dot wisc dot edu Wed Jan 22 23:27:54 2003 Subject: Re: How to input tabular data through a form? From: Paul Kienzle To: "Henry F. Mollet" Cc: "Dmitri A. Sergatskov" , Octave_post Date: Thu, 23 Jan 2003 00:27:25 -0500 This is a multi-part message in MIME format. --Boundary_(ID_v9UrPfjWzJy4RM7cjcvLJQ) Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT Henry F. Mollet wrote: >octave:4> fid=fopen('Workbook1.csv'); >octave:5> a=fscanf(fid,"%f,%f,%f\r",[3,inf]) >a = > > 1 4 7 > 2 5 8 > 3 6 9 > >Finally! Also thanks for hint on how large/complicated a matrix can be. >Henry > There is also dlmread.m from octave-forge (http://octave.sf.net). I'm attaching a copy. I've modified it to support \r, \n, or \r\n line endings, so hopefully it will work for you. Paul Kienzle pkienzle at users dot sf dot net > > --Boundary_(ID_v9UrPfjWzJy4RM7cjcvLJQ) Content-type: text/plain; name=dlmread.m Content-transfer-encoding: 7BIT Content-disposition: inline; filename=dlmread.m ## Copyright (C) 2001 Paul Kienzle ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## x = dlmread (filename, sep) ## Read the matrix x from a file, with columns separated by the ## character sep (default is ","). NaN values are written as nan. ## ## WARNING: for compatibility, must treat empty fields as zero, but doesn't. ## Author: Paul Kienzle ## 2001-02-16 ## * first revision function x = dlmread (filename, sep) if (nargin < 1 || nargin > 2) usage ("x = dlmread (filename, sep)"); endif if nargin < 3, sep = ","; endif fid = fopen(filename, "r"); if (fid >= 0) in = setstr(fread (fid)'); fclose (fid); ## Count the number of line feeds, or if there are none ## the number of carriage returns. This is the number ## of rows. Note that we have to also check for a missing ## line terminator on the last line of the file. idx = find (in == "\n"); nr = length(idx); if (nr > 0) in(idx) = " "; nr += (idx(length(idx)) < length(in)); endif idx = find (in == "\r"); if (nr == 0) nr = length(idx); if (nr > 0) nr += (idx(length(idx)) < length(in)); endif endif if (length (idx) > 0) in(idx) = " "; endif ## convert separators to spaces idx = find (in == sep); if (length(idx) > 0) in(idx) = " "; endif [x, n, err] = sscanf(in, "%g"); if (!isempty(err)) error(["dlmread: ", err]); elseif (rem(n, nr) != 0) error("dlmread: rows are different lengths") else x = reshape(x, n/nr, nr)'; endif else error (["dlmwrite: could not open ", filename]); endif endfunction --Boundary_(ID_v9UrPfjWzJy4RM7cjcvLJQ)-- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------