engineer_eda
Junior Member level 3
Hello,
Could you please help me how to interpret the logical operators in the following Matlab code?
My questions below. I would be glad if you could explain them.
1-Why there is a structure used in the constructor function below?
2-In the constructor function there is a tilde (~) operator, how do we interpret the usage of this tilde operator here?
3-Is there any other way that can be used to express the same purpose here instead of using tilde?
4-Also could you please help interpreting the usage of isstruct operator in the constructor function?
5-What is the meaning of (~isfield(StructParameters)) logical function?
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
Many thanks in advance!!!!
Could you please help me how to interpret the logical operators in the following Matlab code?
My questions below. I would be glad if you could explain them.
1-Why there is a structure used in the constructor function below?
2-In the constructor function there is a tilde (~) operator, how do we interpret the usage of this tilde operator here?
3-Is there any other way that can be used to express the same purpose here instead of using tilde?
4-Also could you please help interpreting the usage of isstruct operator in the constructor function?
5-What is the meaning of (~isfield(StructParameters)) logical function?
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
Many thanks in advance!!!!