Mercurial > hg > ltpda
comparison m-toolbox/classes/@matrix/fromValues.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 % Construct a matrix object with multiple AOs built from input values. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % FUNCTION: fromValues | |
5 % | |
6 % DESCRIPTION: Construct a matrix object with multiple AOs built from input | |
7 % values. | |
8 % | |
9 % CALL: matrix = matrix.fromValues(obj, pli) | |
10 % | |
11 % VERSION: $Id: fromValues.m,v 1.4 2011/03/24 19:53:52 ingo Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 function obj = fromValues(obj, pli, callerIsMethod) | |
15 | |
16 import utils.const.* | |
17 utils.helper.msg(msg.PROC2, 'Constructing an matrix object with multiple AOs built from input values.'); | |
18 | |
19 % get AO info | |
20 ii = matrix.getInfo('matrix', 'From Values'); | |
21 | |
22 pl = combine(pli, ii.plists); | |
23 values = pl.find('values'); | |
24 yunits = pl.find('yunits'); | |
25 names = pl.find('names'); | |
26 | |
27 % Some plausibility checks | |
28 if ~isnumeric(values) | |
29 error('### The values must be from the type double'); | |
30 end | |
31 nvals = numel(values); | |
32 | |
33 if ischar(yunits) | |
34 yunits = cellstr(yunits); | |
35 end | |
36 if numel(yunits) > 1 && numel(yunits) ~= nvals | |
37 error('### The number of yunits must be the same as the numer of values %d <-> %d', numel(yunits), nvals); | |
38 end | |
39 if numel(yunits) == 1 | |
40 % Replicate the single unit for all AOs | |
41 yunits = repmat(yunits, 1, nvals); | |
42 end | |
43 | |
44 if ischar(names) | |
45 names = cellstr(names); | |
46 end | |
47 if numel(names) > 1 && numel(names) ~= nvals | |
48 error('### The number of names must be the same as the numer of values %d <-> %d', numel(names), nvals); | |
49 end | |
50 if numel(names) == 1 | |
51 % Replicate the single name for all AOs | |
52 names = repmat(names, 1, nvals); | |
53 end | |
54 | |
55 for nn = 1:numel(values) | |
56 | |
57 % Create the AO | |
58 a = ao(values(nn)); | |
59 | |
60 % Set the name | |
61 if ~isempty(names) | |
62 a.setName(names{nn}); | |
63 end | |
64 | |
65 % Set the y-units | |
66 if ~isempty(yunits) | |
67 a.setYunits(yunits{nn}); | |
68 end | |
69 | |
70 obj.objs = [obj.objs a]; | |
71 | |
72 end | |
73 | |
74 % Reshape the inside objects | |
75 obj.objs = reshape(obj.objs, size(values)); | |
76 | |
77 % Add history | |
78 if callerIsMethod | |
79 % do nothing | |
80 else | |
81 obj.addHistory(ii, pl, [], []); | |
82 end | |
83 | |
84 warning('off', utils.const.warnings.METHOD_NOT_FOUND); | |
85 % remove parameters we already used | |
86 pl_set = copy(pl,1); | |
87 obj.setProperties(pl_set); | |
88 warning('on', utils.const.warnings.METHOD_NOT_FOUND); | |
89 end |