Mercurial > hg > ltpda
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 classdef (Hidden = true) msym | |
2 | |
3 properties | |
4 s = ''; | |
5 end | |
6 | |
7 | |
8 methods | |
9 | |
10 function ms = msym(varargin) | |
11 | |
12 if isstruct(varargin{1}) | |
13 ms.s = varargin{1}.s; | |
14 else | |
15 | |
16 if ischar(varargin{1}) | |
17 ms.s = varargin{1}; | |
18 elseif isnumeric(varargin{1}) | |
19 ms.s = mat2str(varargin{1}); | |
20 elseif isa(varargin{1}, 'msym') | |
21 ms.s = varargin{1}.s; | |
22 else | |
23 error('### Unknown class [%s] to convert it to a symbolic class.', class(varargin{1})); | |
24 end | |
25 end | |
26 | |
27 end | |
28 | |
29 function display(varargin) | |
30 disp(varargin{1}.s); | |
31 end | |
32 | |
33 function s = char(o) | |
34 s = o.s; | |
35 end | |
36 | |
37 function result = eq(obj1, obj2, varargin) | |
38 result = 1; | |
39 if numel(obj1) ~= numel(obj2) | |
40 utils.helper.msg(utils.const.msg.PROC1, 'NOT EQUAL: The size of the %s-object''s. [%d] <-> [%d]', class(obj1), numel(obj1), numel(obj2)); | |
41 result = 0; | |
42 return | |
43 end | |
44 if ~strcmp(obj1.s, obj2.s) | |
45 utils.helper.msg(utils.const.msg.PROC1, 'NOT EQUAL: %s.%s', class(obj1), 's'); | |
46 result = 0; | |
47 return | |
48 end | |
49 end | |
50 | |
51 function o = subs(o, params, vals) | |
52 if ischar(params) | |
53 params = {params}; | |
54 end | |
55 if isnumeric(vals) | |
56 vals = {vals}; | |
57 end | |
58 if numel(vals) ~= numel(params) | |
59 error('### Please specify one value per parameter'); | |
60 end | |
61 for kk=1:numel(params) | |
62 o.s = regexprep(o.s, ['\<' params{kk} '\>'], mat2str(vals{kk})); | |
63 end | |
64 end | |
65 | |
66 function a = double(o) | |
67 try | |
68 a = eval(o.s); | |
69 catch Me | |
70 disp(Me.message); | |
71 error('### Evaluation of the symbolic expression failed. Perhaps it contains undefined parameters'); | |
72 end | |
73 end | |
74 | |
75 | |
76 | |
77 end | |
78 | |
79 methods (Static = true) | |
80 function obj = initObjectWithSize(n,m) | |
81 obj = msym.newarray([n m]); | |
82 end | |
83 end | |
84 | |
85 methods (Static = true, Hidden = true) | |
86 varargout = loadobj(varargin) | |
87 end | |
88 | |
89 end |