# HG changeset patch
# User Ben Abbott
# Date 1223950212 14400
# Node ID f187e20be3c197f3cd1b084bdd0fff4d450b42ec
# Parent d5e08881bba88fa781db014c8fc8a30710e5ae90
ishandle_with_props.m: New function ishandle_with_props().
diff -r d5e08881bba8 -r f187e20be3c1 scripts/ChangeLog
--- a/scripts/ChangeLog Sun Oct 12 15:28:00 2008 +0100
+++ b/scripts/ChangeLog Mon Oct 13 22:10:12 2008 -0400
@@ -1,3 +1,7 @@
+2008-10-13 Ben Abbott
+
+ * plot/ishandle_with_props.m: New function ishandle_with_props().
+
2008-10-12 David Bateman
* general/colon..m: New function.
diff -r d5e08881bba8 -r f187e20be3c1 scripts/plot/Makefile.in
--- a/scripts/plot/Makefile.in Sun Oct 12 15:28:00 2008 +0100
+++ b/scripts/plot/Makefile.in Mon Oct 13 22:10:12 2008 -0400
@@ -124,6 +124,7 @@
hist.m \
hold.m \
isfigure.m \
+ ishandle_with_props.m \
ishghandle.m \
ishold.m \
legend.m \
diff -r d5e08881bba8 -r f187e20be3c1 scripts/plot/ishandle_with_props.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/plot/ishandle_with_props.m Mon Oct 13 22:10:12 2008 -0400
@@ -0,0 +1,84 @@
+## Copyright (C) 2008 Ben Abbott
+##
+## 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 Octave; see the file COPYING. If not, see
+## .
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} ishandle_with_props (@var{h})
+## @deftypefnx {Function File} {} ishandle_with_props (@var{h}, @var{p1}, @var{v1})
+## @deftypefnx {Function File} {} ishandle_with_props (@var{h}, @var{p1}, @var{v1}, @var{p2}, @var{v2}, @dots{})
+## Return true if @var{h} is a handle with the specified properties, @var{pn},
+## and values, @var{vn}, and false otherwise. The specified properties
+## must represent character, scalar, vector, or other ND-array data.
+## @end deftypefn
+
+## Author: Ben Abbott address@hidden
+## Created: 2008-10-12
+
+function [ ret ] = ishandle_with_props (h, varargin)
+
+ ret = ishandle (h);
+
+ if any (ret)
+ for n = 1:2:numel(varargin)
+ m = find (ret);
+ prop = varargin{n};
+ value = varargin{n+1};
+ values = get (h(m), prop);
+ if (! iscell (values))
+ ## if there is only one handle left, cells are not returned by get().
+ values = {values};
+ endif
+ if ischar(value)
+ w = strcmpi (value, values);
+ elseif (isscalar (value))
+ w = cell2mat (values) == value;
+ else
+ w = logical (zeros (size (values)) == 1);
+ for nv = 1:numel(values)
+ if all (size (value) == size (values{nv}))
+ w(nv) = all (value(:) == values{nv}(:));
+ else
+ w(nv) = false;
+ endif
+ endfor
+ endif
+ ret(m) = (w(:) & ret(m));
+ endfor
+ endif
+
+endfunction
+
+%!test
+%! figure (1)
+%! clf
+%! h(1) = subplot(211);
+%! h(2) = subplot(212);
+%! h(3) = axes;
+%! h = h(:);
+%! set (h(3), "position", get (h(1), "position"));
+%! assert (ishandle_with_props (h, "type", "axes"), [true; true; true]);
+
+%!test
+%! figure (1)
+%! clf
+%! h(1) = subplot(211);
+%! h(2) = subplot(212);
+%! h(3) = axes;
+%! h = h(:);
+%! set (h(3), "activepositionproperty", "position")
+%! set (h(3), "position", get (h(1), "position"));
+%! result = ishandle_with_props (h, "type", "axes", "position", get (h(1), "position"));
+%! assert (result, [true; false; true]);
+