Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@helper/classFromStruct.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 % CLASSFROMSTRUCT returns a class name that matches the structure. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: CLASSFROMSTRUCT returns a class name that matches the | |
5 % structure. | |
6 % | |
7 % CALL: class_name = classFromStruct(struct) | |
8 % | |
9 % If structure does not match any of the LTPDA classes, then 'class_name' | |
10 % will be empty. | |
11 % | |
12 % INPUTS: struct: Structure which should be checked | |
13 % | |
14 % OUTPUTS: class_name: Class name. | |
15 % | |
16 % VERSION: $Id: classFromStruct.m,v 1.2 2009/07/22 14:45:17 ingo Exp $ | |
17 % | |
18 % HISTORY: 08-09-08 M Hewitson | |
19 % Creation | |
20 % | |
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
22 | |
23 function varargout = classFromStruct(varargin) | |
24 | |
25 if nargin < 1 | |
26 error('### Unknown number of inputs.%s### Please use: classFromStruct(struct)', char(10)) | |
27 end | |
28 | |
29 obj_struct = varargin{1}; | |
30 class_name = ''; | |
31 % we must determine the class from the fieldnames | |
32 cls = utils.helper.ltpda_non_abstract_classes; | |
33 snames = fieldnames(obj_struct); | |
34 for jj=1:numel(cls) | |
35 cl = cls{jj}; | |
36 cnames = properties(cl); | |
37 if numel(cnames) == numel(snames)&& all(strcmp(snames, cnames)) | |
38 class_name = cl; | |
39 break; | |
40 end | |
41 end | |
42 | |
43 % Set output | |
44 varargout{1} = class_name; | |
45 | |
46 end |