diff m-toolbox/classes/@msym/msym.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/@msym/msym.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,89 @@
+classdef (Hidden = true) msym
+  
+  properties
+    s = '';
+  end
+  
+  
+  methods
+    
+    function ms = msym(varargin)
+      
+      if isstruct(varargin{1})
+        ms.s = varargin{1}.s;
+      else
+        
+        if ischar(varargin{1})
+          ms.s = varargin{1};
+        elseif isnumeric(varargin{1})
+          ms.s = mat2str(varargin{1});
+        elseif isa(varargin{1}, 'msym')
+          ms.s = varargin{1}.s;
+        else
+          error('### Unknown class [%s] to convert it to a symbolic class.', class(varargin{1}));
+        end
+      end
+      
+    end
+    
+    function display(varargin)
+      disp(varargin{1}.s);
+    end
+    
+    function s = char(o)
+      s = o.s;
+    end
+    
+    function result = eq(obj1, obj2, varargin)
+      result = 1;
+      if numel(obj1) ~= numel(obj2)
+        utils.helper.msg(utils.const.msg.PROC1, 'NOT EQUAL: The size of the %s-object''s. [%d] <-> [%d]', class(obj1), numel(obj1), numel(obj2));
+        result = 0;
+        return
+      end
+      if ~strcmp(obj1.s, obj2.s)
+        utils.helper.msg(utils.const.msg.PROC1, 'NOT EQUAL: %s.%s', class(obj1), 's');
+        result = 0;
+        return
+      end
+    end
+    
+    function o = subs(o, params, vals)
+      if ischar(params)
+        params = {params};
+      end
+      if isnumeric(vals)
+        vals = {vals};
+      end
+      if numel(vals) ~= numel(params)
+        error('### Please specify one value per parameter');
+      end
+      for kk=1:numel(params)
+        o.s = regexprep(o.s, ['\<' params{kk} '\>'], mat2str(vals{kk}));
+      end
+    end
+    
+    function a = double(o)
+      try
+        a = eval(o.s);
+      catch Me
+        disp(Me.message);
+        error('### Evaluation of the symbolic expression failed. Perhaps it contains undefined parameters');
+      end
+    end
+    
+    
+    
+  end
+  
+  methods (Static = true)
+    function obj = initObjectWithSize(n,m)
+      obj = msym.newarray([n m]);
+    end
+  end
+  
+  methods (Static = true, Hidden = true)
+    varargout = loadobj(varargin)
+  end
+    
+end