- function ErrorVal = HeightCorrection(tank)
- function Err = OutOfBoundsCorrection(obj)
OOP: passing arguments to a handle class method
4 views (last 30 days)
Show older comments
Hi,
I'm writing a method that takes a double data type (from a property of a local class object) and then does some calculations with it:
function Err = OutOfBoundsCorrection(obj)
% determine error to add to species for exceeding system limits
ErrorVal = zeros(2,2); % initialise array to hold error values
ErrorVal(1,1) = HeightCorrection(obj.SimTankA.Height); % error from tank A height being too low or high
ErrorVal(2,1) = TempCorrection(obj.SimTankA.Temp); % error from tank A temp being too low or high
ErrorVal(1,2) = HeightCorrection(obj.SimTankB.Height); % error from tank B height being too low or high
ErrorVal(2,2) = TempCorrection(obj.SimTankB.Temp); % error from tank B temp being too low or high
Err = sum(ErrorVal); % sum errors together
end
function ErrorVal = HeightCorrection(tank)
% determine error from tank height approaching or exceeding bounds
if (tank < 0.2) % fluid height is below 0.2 metres -> MIN 0
ErrorVal = 100 * 1/tank; % inverse of height by an arbitary penalty
else if (tank > 2.3) % fluid height is above 2.3 metres - > MAX 2.5
ErrorVal = 10000 * (tank - 2.3); % remove offset and multiply by arbitrary penalty
end
end
end
However i keep getting an error message from matlab: 'Undefined function 'HeightCorrection' for input arguments of type 'double'. Not sure what's causing this. Something to do with the way I'm calling the property, or writing the argument term in the method?
Has anyone got suggestions?
0 Comments
Accepted Answer
per isakson
on 14 Aug 2012
Edited: per isakson
on 14 Aug 2012
I assume that
each defines a method (not static) of a class. If so the syntax of the call should be
ErrorVal(1,1) = HeightCorrection( obj, obj.SimTankA.Height );
or
ErrorVal(1,1) = obj.HeightCorrection(obj.SimTankA.Height);
and the signature of the method should be
function ErrorVal = HeightCorrection( obj, tank )
.
It is possible to keep the code as is and make, HeightCorrection, an ordinary separate function.
More Answers (0)
See Also
Categories
Find more on Performance and Memory in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!