I need help with my code for a degree in IT
Show older comments
CODE 1:
classdef SurfaceUnit
properties (Access = private)
Position
Threat
Certainty
end
methods
function obj = SurfaceUnit(varargin)
if nargin == 3
obj.Position = varargin{1};
obj.Threat = varargin{2};
obj.Certainty = varargin{3};
else
unit1 = SurfaceUnit([10,20],'FRD',0.9);
end
end
function out = getPosition(obj)
function setPosition(obj, p)
function out = getTreat(obj)
function setThreat(obj, t)
function out = getCertainty(obj)
function setCertainty(obj, c)
end
end
end
end
end
end
end
end
CODE 2:
classdef AttributeFusion
properties
Unit1
Unit2
FusedUnit
end
methods
function obj = AttributeFusion(u1,u2)
obj.Unit1 = u1;
obj.Unit2 = u2;
obj.FusedUnit = SurfaceUnit;
end
function out = getFusedUnit(obj)
out = obj.FusedUnit;
end
end
end
CODE 3:
clear; clc;
unit1 = SurfaceUnit([10,20],ThreatValues.FRD,0.9);
unit2 = SurfaceUnit([15,25],ThreatValues.ASF,0.8);
fision = AttributeFusion(unit1, unit2);
fusedUnit = fusion.getFusedUnit;
fusedUnit.getPosition
char(fusedUnit.getThreat)
Well the problem is, that I do not know why my program says that obj section is unused and it may require replacing it with ~.
Answers (1)
Walter Roberson
on 19 Oct 2024
function out = getPosition(obj)
function setPosition(obj, p)
function out = getTreat(obj)
function setThreat(obj, t)
function out = getCertainty(obj)
function setCertainty(obj, c)
end
end
end
end
end
end
Those are nested function definitions. setPosition is defined inside of getPosition, getTreat is defined inside of setPosition, and so on. None of the implementations use the input obj so MATLAB warns you that input obj is unused.
You are quite unlikely to want nested function definitions at that point.
2 Comments
Wiktor
on 19 Oct 2024
Walter Roberson
on 19 Oct 2024
function out = getPosition(obj)
end
function setPosition(obj, p)
end
and so on.
Then populate the bodies of the functions with appropriate code, such as
out = obj.Position;
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!