# HG changeset patch # User Ben Abbott # Date 1378570898 14400 # Node ID e04847bbcfdfe6cf98301f06021b2310afded3eb # Parent 2b4ed68be0d5f082babd2817f7280b2ea0b62b9f Squeeze Nd > 2 plot vectors. * scripts/plot/__plt__.m: Squeeze input plot vectors when ndims>2. Throw error if there are more than 2 non-singleton dimensions. * scripts/plot/plot.m: Modify doc-string. Add demos. diff -r 2b4ed68be0d5 -r e04847bbcfdf scripts/plot/plot.m --- a/scripts/plot/plot.m Fri Sep 06 19:42:13 2013 -0400 +++ b/scripts/plot/plot.m Sat Sep 07 12:21:38 2013 -0400 @@ -69,6 +69,10 @@ ## ## @item ## If @var{x} and @var{y} are scalars, a single point is plotted. +## +## @item +## @code{squeeze()} is applied to arguments with more than two dimensions, +## but no more than two singleton dimensions. ## ## @item ## If both arguments are vectors, the elements of @var{y} are plotted versus @@ -245,3 +249,37 @@ %! title ({'plot() of blue circles ascending and red squares descending'; %! 'connecting lines drawn'}); +%!demo +%! x = 0:10; +%! plot (x, rand (numel (x), 3)) +%! axis ([0 10 0 1]) +%! title ({'Three random variables', 'x[1x11], y[11x3]'}) + +%!demo +%! x = 0:10; +%! plot (x, rand (3, numel (x))) +%! axis ([0 10 0 1]) +%! title ({'Three random variables', 'x[1x11], y[3x11]'}) + +%!demo +%! x = 0:10; +%! plot (repmat (x, 2, 1), rand (2, numel (x)), '-s') +%! axis ([0 10 0 1]) +%! title ({'Vertical lines with random height and lenths', ... +%! 'x[2x11], y[2,11]'}) + +%!demo +%! x = 0:10; +%! plot (repmat (x(:), 1, 2), rand (numel (x), 2)) +%! axis ([0 10 0 1]) +%! title ({'Two random variables', 'x[11x2], y[11x2]'}) + +%!demo +%! x = 0:10; +%! shape = [1, 1, numel(x), 2]; +%! x = reshape (repmat (x(:), 1, 2), shape); +%! y = rand (shape); +%! plot (x, y) +%! axis ([0 10 0 1]) +%! title ({'Two random variables', 'squeezed from 4-d arrays'}) + diff -r 2b4ed68be0d5 -r e04847bbcfdf scripts/plot/private/__plt__.m --- a/scripts/plot/private/__plt__.m Fri Sep 06 19:42:13 2013 -0400 +++ b/scripts/plot/private/__plt__.m Sat Sep 07 12:21:38 2013 -0400 @@ -25,6 +25,7 @@ function retval = __plt__ (caller, h, varargin) + persistent warned_callers = {}; nargs = nargin - 2; if (nargs > 0) @@ -72,6 +73,19 @@ next_arg = varargin{k++}; endif + if (isnumeric (next_arg) && ndims (next_arg) > 2 + && any (size (next_arg) == 1)) + next_arg = squeeze (next_arg); + if (! any (strcmp (caller, warned_callers)) && ndims (next_arg) < 3) + warning (["%s: N-d inputs have been squeezed to less than " ... + "three dimensions"], caller) + warned_callers(end+1) = caller; + endif + endif + if (isnumeric (next_arg) && ndims (next_arg) > 2) + error ("%s: plot arrays must have less than 2 dimensions", caller) + endif + nargs--; if (ischar (next_arg) || iscellstr (next_arg))