# HG changeset patch # User jwe # Date 1086304274 0 # Node ID 89eee52fd4c798cebda9a5d0676bb467b16c9cce # Parent b8a5e0bc63fe111d2edde4675088fcfee9000192 [project @ 2004-06-03 23:07:55 by jwe] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2004-06-03 Paul Kienzle + + * plot/__errcomm__.m, plot/__errplot__.m: Simplify code and fix + the bug which causes __errplot__ to ignore the last argument. + 2004-06-03 David Bateman * general/shiftdim.m: New function based on JWE code snippet. diff --git a/scripts/plot/__errcomm__.m b/scripts/plot/__errcomm__.m --- a/scripts/plot/__errcomm__.m +++ b/scripts/plot/__errcomm__.m @@ -31,13 +31,11 @@ function __errcomm__ (caller, varargin) - nargs = nargin (); - - if (nargs < 3) - usage ("%s (...)", caller); + if (nargin < 3) + usage ("%s (x,y,dy,'fmt',...)", caller); endif - nargs--; + nargs = length (varargin); save_hold = ishold; unwind_protect if (! ishold) @@ -45,9 +43,9 @@ endif hold on; k = 1; - while (nargs-- > 0) + data = cell(6,1); + while (k <= nargs) a = varargin{k++}; - nargs--; if (isvector (a)) a = a(:); elseif (ismatrix (a)) @@ -57,16 +55,11 @@ endif sz = size (a); ndata = 1; - arg1 = a; - while (nargs-- > 0) + data{ndata} = a; + while (k <= nargs) a = varargin{k++}; if (isstr (a)) - fmt = a; - cmd = "__errplot__ (arg1"; - for i = 2:ndata, - cmd = sprintf ("%s, arg%d", cmd, i); - endfor - eval (sprintf ("%s, fmt);", cmd)); + __errplot__ (a, data{1:ndata}); break; elseif (isvector (a)) a = a(:); @@ -78,8 +71,7 @@ if (size (a) != sz) error ("argument sizes do not match"); endif - ndata++; - eval (sprintf ("arg%d = a;", ndata)); + data{++ndata} = a; if (ndata > 6) error ("too many arguments to a plot"); endif @@ -87,12 +79,7 @@ endwhile if (! isstr (a)) - fmt = "~"; - cmd = "__errplot__ (arg1"; - for i = 2:ndata, - cmd = sprintf ("%s, arg%d", cmd, i); - endfor - eval (sprintf ("%s, fmt);", cmd)); + __errplot__ ("~", data{1:ndata}); endif unwind_protect_cleanup if (! save_hold) diff --git a/scripts/plot/__errplot__.m b/scripts/plot/__errplot__.m --- a/scripts/plot/__errplot__.m +++ b/scripts/plot/__errplot__.m @@ -33,81 +33,41 @@ ## Author: Teemu Ikonen ## Keywords: errorbar, plotting -function __errplot__ (varargin) - - nargs = nargin (); - - if (nargs < 3) # atleast two data arguments needed - usage ("__errplot__ (arg1, ..., fmt)"); - endif +function __errplot__ (fstr,a1,a2,a3,a4,a5,a6) - fstr = " "; - ndata = 0; - k = 1; - - while (nargs--) - a = varargin{k++}; - if (! isstr (a)) - ndata++; - eval (sprintf ("arg%d = a;", ndata)); - else - fstr = a; - endif - endwhile + if (nargin < 3 || nargin > 7) # at least three data arguments needed + usage ("__errplot__ (fmt, arg1, ...)"); + endif fmt = __pltopt__ ("__errplot__", fstr); - nplots = size (arg1, 2); - len = size (arg1, 1); - - if (ndata == 2) - for i = 1:nplots, - tmp = [(1:len)', arg1(:,i), arg2(:,i)]; - cmd = sprintf ("gplot tmp %s", fmt(min(i, rows(fmt)), :)); - eval (cmd); - endfor - elseif (ndata == 3) - for i = 1:nplots, - tstr = "tmp =[arg1(:,i)"; - for j = 2:ndata, - tstr = [tstr, sprintf(", arg%d(:,i)", j)]; - endfor - tstr = [tstr, "];"]; - eval (tstr); - cmd = sprintf ("gplot tmp %s", fmt(min(i, rows(fmt)), :)); - eval (cmd); - endfor - elseif (ndata == 4) - for i = 1:nplots, # this is getting ugly - if (index (fmt, "boxxy") || index (fmt, "xyerr")) - tstr = "tmp = [arg1(:,i), arg2(:,i), arg3(:,i), arg4(:,i)];"; - elseif (index (fmt, "xerr")) - tstr = "tmp = [arg1(:,i), arg2(:,i), arg1(:,i)-arg3(:,i), arg1(:,i)+arg4(:,i)];"; - else - tstr = "tmp = [arg1(:,i), arg2(:,i), arg2(:,i)-arg3(:,i), arg2(:,i)+arg4(:,i)];"; - endif - eval (tstr); - cmd = sprintf ("gplot tmp %s", fmt(min(i, rows(fmt)), :)); - eval (cmd); - endfor - elseif (ndata == 6) - for i = 1:nplots, - tstr = "tmp = [arg1(:,i), arg2(:,i), arg1(:,i)-arg3(:,i), arg1(:,i)+arg4(:,i), arg2(:,i)-arg5(:,i), arg2(:,i)+arg6(:,i)];"; - eval (tstr); - cmd = sprintf ("gplot tmp %s", fmt(min(i, rows(fmt)), :)); - eval (cmd); - endfor - else - for i = 1:nplots, - tstr = "tmp = [arg1(:,i)"; - for j = 2:ndata, - tstr = [tstr, sprintf(", arg%d(:,i)", j)]; - endfor - tstr = [tstr, "];"]; - eval (tstr); - cmd = sprintf ("gplot tmp %s", fmt(min(i, rows(fmt)), :)); - eval (cmd); - endfor - endif + nplots = size (a1, 2); + len = size (a1, 1); + for i = 1:nplots + ifmt = fmt(1+mod(i,size(fmt,1)), :); + switch (nargin - 1) + case 2 + tmp = [(1:len)', a1(:,i), a2(:,i)]; + case 3 + tmp = [a1(:,i), a2(:,i), a3(:,i)]; + case 4 + if (index (ifmt, "boxxy") || index (ifmt, "xyerr")) + tmp = [a1(:,i), a2(:,i), a3(:,i), a4(:,i)]; + elseif (index (ifmt, "xerr")) + tmp = [a1(:,i), a2(:,i), a1(:,i)-a3(:,i), a1(:,i)+a4(:,i)]; + else + tmp = [a1(:,i), a2(:,i), a2(:,i)-a3(:,i), a2(:,i)+a4(:,i)]; + endif + case 5 + error ("error plot requires 2, 3, 4 or 6 columns"); + ## tmp = [a1(:,i), a2(:,i), a3(:,i), a4(:,i), a5(:,i)]; + case 6 + tmp = [a1(:,i), a2(:,i), ... + a1(:,i)-a3(:,i), a1(:,i)+a4(:,i), ... + a2(:,i)-a5(:,i), a2(:,i)+a6(:,i)]; + endswitch + cmd = sprintf ("gplot tmp %s", ifmt); + eval (cmd); +endfor endfunction diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2004-06-03 David Bateman + + * DLD-FUNCTIONS/filter.cc: Fix for length(a)=1 && length(b)=2 case. + 2004-05-07 John W. Eaton * ov.cc (octave_value::print_with_name): Only print name tag if diff --git a/src/DLD-FUNCTIONS/filter.cc b/src/DLD-FUNCTIONS/filter.cc --- a/src/DLD-FUNCTIONS/filter.cc +++ b/src/DLD-FUNCTIONS/filter.cc @@ -113,7 +113,7 @@ b = b / norm; } - if ((a_len <= 1) && (si_len <= 1)) + if ((a_len <= 1) && (si_len <= 0)) return b(0) * x; y.resize (x_dims, 0.0);