diff m-toolbox/classes/@param/setDefaultIndex.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/@param/setDefaultIndex.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,40 @@
+% SETDEFAULTINDEX Sets the index which points to the default value to the input.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION: SETDEFAULTINDEX Sets the index which points to the default
+%              value to the input.
+%
+% CALL:        obj = obj.setDefaultIndex(index);
+%
+% INPUTS:      obj   - A single param object
+%              index - An index to the default option which should to be set.
+%
+% VERSION:     $Id: setDefaultIndex.m,v 1.2 2011/02/22 15:51:44 hewitson Exp $
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function p = setDefaultIndex(p, index)
+  
+  % Check input
+  if numel(p) ~= 1
+    error('### This method works only with one input parameter object.');
+  end
+  if ~isnumeric(index) && numel(index) ~= 1
+    error('### This method works only with one input index.');
+  end
+  
+  % Make a copy if the user doesn't use the modifier command
+  p = copy(p, nargout);
+  
+  if isa(p.val, 'paramValue')
+    if numel(p.val.options) >= index
+      p.val.setValIndex(index);
+    else
+      error('### The number of param-options [%d] is for the new index [%d] not enough.', numel(p.val.options), index);
+    end
+  else
+    warning('!!! This parameter [%s] has no options', p.key);
+  end
+  
+end
+