Mercurial > hg > ltpda
diff m-toolbox/classes/@ltpda_uo/fromModel.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children | bc767aaa99a8 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/@ltpda_uo/fromModel.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,56 @@ +% FROMMODEL Construct an a built in model +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% FUNCTION: fromModel +% +% DESCRIPTION: Construct an ltpda uder objects with history from a +% built-in model +% +% CALL: a = fromModel(a, pl) +% +% PARAMETER: pl: Parameter list object +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +function [obj, ii, fcnname] = fromModel(obj, pl) + + % Get the name of the model the user wants + model = find(pl, 'built-in'); + + % Get a list of user model directories + paths = utils.models.getBuiltinModelSearchPaths(); + + for jj = 1:numel(paths) + utils.helper.msg(utils.const.msg.PROC1, 'looking for models in %s', paths{jj}); + end + + % Give an error if the model name is a number + if isnumeric(model) + error(['### This syntax is no more supported. Please choose a model from the list you can obtain with: ' ... + '''%s.getBuiltInModels'''], class(obj)); + end + + % Give an error if the model name is empty + if isempty(model) + error(['### No model specified. Please choose one from the list you can obtain with: ' ... + '''%s.getBuiltInModels'''], class(obj)); + end + + % Find the matching model + try + fcnname = sprintf('%s_model_%s', class(obj), model); + ii = obj.getInfo(class(obj), 'From Built-in Model'); + [obj, pl] = feval(fcnname, pl, ii); + catch ME + if strcmp(ME.identifier, 'MATLAB:UndefinedFunction') && length(ME.stack) == 3 + % If the model is missing, tell the user + error(['### Model named ''%s'' not found. Please choose one from the list you can obtain with: ' ... + '''%s.getBuiltInModels'''], model, class(obj)); + else + % If the error is different, just notify the user + rethrow(ME); + end + end + +end +