X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fstatistics-1.1.3%2Fcasewrite.m;fp=octave_packages%2Fstatistics-1.1.3%2Fcasewrite.m;h=6219670b09e0a953279e4ec0a02f737115d0a959;hp=0000000000000000000000000000000000000000;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/statistics-1.1.3/casewrite.m b/octave_packages/statistics-1.1.3/casewrite.m new file mode 100644 index 0000000..6219670 --- /dev/null +++ b/octave_packages/statistics-1.1.3/casewrite.m @@ -0,0 +1,66 @@ +## Copyright (C) 2008 Bill Denney +## +## 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 3 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, see . + +## -*- texinfo -*- +## @deftypefn {Function File} {} casewrite (@var{strmat}, @var{filename}) +## Write case names to an ascii file. +## +## Essentially, this writes all lines from @var{strmat} to +## @var{filename} (after deblanking them). +## @seealso{caseread, tblread, tblwrite, csv2cell, cell2csv, fopen} +## @end deftypefn + +## Author: Bill Denney +## Description: Write strings from a file + +function names = casewrite (s="", f="") + + ## Check arguments + if nargin != 2 + print_usage (); + endif + if isempty (f) + ## FIXME: open a file dialog box in this case when a file dialog box + ## becomes available + error ("casewrite: filename must be given") + endif + if isempty (s) + error ("casewrite: strmat must be given") + elseif ! ischar (s) + error ("casewrite: strmat must be a character matrix") + elseif ndims (s) != 2 + error ("casewrite: strmat must be two dimensional") + endif + + [fid msg] = fopen (f, "wt"); + if fid < 0 || (! isempty (msg)) + error ("casewrite: cannot open %s for writing: %s", f, msg); + endif + + for i = 1:rows (s) + status = fputs (fid, sprintf ("%s\n", deblank (s(i,:)))); + endfor + if (fclose (fid) < 0) + error ("casewrite: error closing f") + endif + +endfunction + +## Tests +%!shared s +%! s = ["a ";"bcd";"ef "]; +%!test +%! casewrite (s, "casewrite.dat") +%! assert(caseread ("casewrite.dat"), s);