matlab can’t change parameters of a class while in a constructor

The issue here is that you are using a value class, not a handle class. Note that in your Velocity method you are returning an instance of “self”, in a value class these method invocations return a separate object, which is being ignored in this code.

That being said two possible solutions:

  1. Capture output of value objects and return the final, modified object.

     function self = piping(flowRate, diameter, startLocation, endLocation)
         % ...
         self = self.calculateCalculatedProperties();      
     end
    
     function self = calculateCalculatedProperties(self)
         fprintf("hey")
         self = self.Velocity();
         self = self.Length();
     end
    
  2. Use handle classes to create a mutable object.

     classdef piping < handle
         % ...
     end
    

See Comparison of Handle and Value Classes for more info.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top