I am calling a function to change parameters of my class inside its constructor, however, I can't change the values. Is this a bug or on purpose?
In the following example, I am calling function "calculateCalculatedProperties()" inside constructor. "calculateCalculatedProperties()" calls "Velocity()" and "Length()" function which sets new values of velocity and length properties. However, at the end product of the constructor (object instance) properties are unchanged.
classdef piping
%PIPING Summary of this class goes here
% Detailed explanation goes here
properties
flowRate
diameter
startLocation location
endLocation location
end
methods
function self = piping(flowRate, diameter, startLocation, endLocation)
self.flowRate = flowRate;
self.diameter = diameter;
self.startLocation = startLocation;
self.endLocation = endLocation;
self.calculateCalculatedProperties();
end
function self = calculateCalculatedProperties(self)
fprintf("hey")
self.Velocity();
self.Length();
end
function self = Velocity(self)
self.velocity = self.flowRate / (pi * self.diameter^2 / 4);
end
function self = Length(self)
self.length = location.calculateDistance(self.startLocation,self.endLocation) ;
fprintf("hey this is lengthhhh")
self.flowRate = 10000000;
end
end
properties % Calculated properties
velocity
length
end
end