> b = > > '2' > ''
OK, I'm almost there but I'm blocked by a last problem with vectors of strings. I'm not able to create a vector b as above. I receive the following error: a=cell(2);a{1}="2";a{2}=""; b=cell(2,1); b=a{1,:} error: invalid assignment of comma-separated list how can I extract a vector of strings from a cell array? here is the status of textread.m: function varargout = textread(file, formatstr, prop, val) ## -*- texinfo -*- ## @deftypefn {Function File} {...@var{a} @var{b} ...]=}textread(@var{filename},@var{format}) ## @deftypefnx {Function File} {...@var{a} @var{b} ...] =}textread(@var{filename},@var{format},@var{prop},@var{value}) ## Read data from a text file. ## The string @var{format} describes the different columns of the text file and ## It may continue the following specifiers: ## @table @code ## @item %s ## for a string, ## ## @item %d,%f ## for a double, floating-point or integer number and ## ## @item %* ## to ignore a column. ## @end table ## ## For example, the textfile containing ## ## @example ## @group ## Bunny Bugs 5.5 ## Duck Daffy -7.5e-5 ## Penguin Tux 6 ## @end group ## @end example ## ## can be read using ## ## @example ## @code{[a,b,c] = textread("test.txt", "%s %s %f").} ## @end example ## ## @end deftypefn ## @seealso{load, dlmread, fscanf} ## Currently implemented @var{prop} arguments are: ## @itemize ## @item \"headerlines\": ## @var{value} represents the number of header lines to skip. ## @end itemize ## Copyright (C) 2009 Eric Chassande-Mottin, CNRS (France) ## 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 . if nargchk(2,4,nargin) usage("textread.m: r = textread( filename, format, [prop, val] )"); end; comment_flag=false; if nargin>2 switch prop case "commentstyle" comment_flag=true; switch val case "c" comment_specif="/*"; case "c++" comment_specif="//"; case "shell" comment_specif="#"; case "matlab" comment_specif="%"; otherwise error("textread: unknown comment style %s",val); endswitch endswitch endif # open file fid = fopen(file,"r"); # parse format string idx=strfind(formatstr,"%")'; specif=formatstr([idx,idx+1]); n=length(idx); if (nargout!=n) error("textread: the number of output variables must match that of format specifiers"); endif # read line k=1; while ~feof(fid) this = fgetl(fid); if isempty(this) continue endif this=deblank(this); ## ignore line if it is a comment if comment_flag buffer=strjust(this,"left"); if strcmp(buffer(1:length(comment_specif)),comment_specif) continue endif endif while ~isempty(this) m=1; while (m <= n) ## read data data=sscanf(this,"%s",1); ## if no data if isempty(data) switch specif(m,:) case "%s" res{m,k}=""; case "%d" res{m,k}=[]; case "%f" res{m,k}=[]; endswitch m++; continue endif ## map to format switch specif(m,:) case "%s" res{m,k}=char(data); case "%d" res{m,k}=str2num(data); case "%f" res{m,k}=str2num(data); endswitch ## suppress read data from buffer this=this(length(data)+2:end); m++; endwhile ## m <= n k++; endwhile ## ~isempty(this) endwhile ## ~feof(fid) ## map to output structures for m=1:n switch specif(m,:) case "%s" varargout{m}=res{m,:}; case "%d" varargout{m}=[res{m,:}]; case "%f" varargout{m}=[res{m,:}]; endswitch endfor ## close file fclose(fid); endfunction ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev