Error defining single class property in Enumeration Class
Afficher commentaires plus anciens
Hello everyone, I am struggling to find how to make this work in MATLAB.
I have an Enumeration Class, which has its enumerators plus a single class property which is a function pointer to some (same class) Static Functions. In other words, depending on the enumerator value, the function pointer will point to its related function, so that I can then have an ```evaluate()``` function which calls the function pointer under the hood.
Here is the idea:
classdef PSDType < handle
enumeration
DAVENPORT (PSDType.DavenportPSD)
VON_KARMAN (PSDType.VonKarmanPSD)
KAIMAL (PSDType.KaimalPSD)
EUROCODE (PSDType.EurocodePSD)
ORNSTEIN_UHLENBECK (PSDType.OU_PSD)
end
properties (Access = private)
func_ptr function_handle
end
methods (Access = public)
function S = evaluate(this, varargin)
try
S = this.func_ptr(varargin{:});
catch ex
warning('\n%s', ...
'@PSDType.evaluate: exception evaluating PSD');
getReport(ex);
end
end
end
methods (Static = true)
... here static methods to point to
end
end
However, once I run, as soon as it load into memory the Class which has as one of its member functions this Enumeration Class instance, I get this error
Invalid default value for property 'PSD_TYPE' in class 'WindData':
Not enough input arguments.
memb PSDType = PSDType.DAVENPORT % (default initialisation in class member instance)
I even added the Class constructor:
function this = PSDType(f_ptr)
this.func_ptr = f_ptr;
end
with no changes.
What do I do wrong?
Thanks a lot for your answers!
Réponse acceptée
Plus de réponses (1)
classdef PSDType
enumeration
DAVENPORT
VON_KARMAN
KAIMAL
EUROCODE
ORNSTEIN_UHLENBECK
end
methods (Access = public)
function obj = PSDType()
% constructor
end
function s = evaluate(obj, varargin)
s = [];
switch obj
case PSDType.DAVENPORT
s = obj.callDavenPort(varargin);
case PSDType.VON_KARMAN
case PSDType.KAIMAL
case PSDType.EUROCODE
case PSDType.ORNSTEIN_UHLENBECK
end
end
end
methods (Access = 'private')
function s = callDavenPort(obj,varargin)
s = "evalDavenPort";
end
end
end
How about this ?
PSDType.DAVENPORT.evaluate
"evalDavenPort"
Catégories
En savoir plus sur Methods dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!