It has the constructor function to pass the data into the myClass variables (a,d,noInput) and the constructor has
the data structure (StructParameters). As I understand so far,
by using the data structure (StructParameters) the constructor function passes the data into the myClass variables.
- What is the purpose of using if-else condition with StructParameters.noInput? what is the meaning of that in this Matlab code?
- How can I access into the structured data, StructParameters?
- How can I run the following error condition? Any exaple commands for this?
***error('Input argument has to be struct.')
Many thanks in advance!!!
Expand|Select|Wrap|Line Numbers
- classdef myClass
- properties
- a;
- d;
- noInput;
- end
- methods
- function obj=myClass(StructParameters)
- if nargin==0
- StructParameters.noInput=1;
- else
- StructParameters.noInput=0;
- end
- if ~isstruct(StructParameters)
- error('Input argument has to be struct.')
- else
- % load the parameters
- F=fields(StructParameters);
- for x=1:length(F)
- obj.(F{x})=StructParameters.(F{x});
- end
- end
- if ~isfield(StructParameters, 'a')
- obj.a=[1 2; 4 5];
- end
- if ~isfield(StructParameters, 'd')
- obj.d=[0 1; 4 5];
- end
- end
- end
- end