0

I am trying to save functions as variables inside a class so I can reach them in an ordered manner. However, whenever I try to pull any constant from the following class, I get the following error.

    %FORMULAS Summary of this class goes here
    %   Detailed explanation goes here
    
    properties (Constant)
       
        %F.heatCapacityOfLiquid
        t = @(z) z *2
    end
    
    properties (Constant)
        enthalpyChange =  @(constants, temperatureIn, temperatureOut)integral(@(temperature)(@(constants, temperature)...
            constants(1)...
            + temperature * constants(2)... 
            + temperature.^2 * constants(3)...
            + temperature.^3 * constants(4)), 0,10);
  
         heatCapacityOfLiquid = @(constants, temperature) constants(1)...
            + temperature * constants(2)... 
            + temperature.^2 * constants(3)...
            + temperature.^3 * constants(4);
    end
    



end

ERROR

>> F.t
Invalid default value for property 'enthalpyChange' in class 'F':
Error: Invalid use of operator.
RedGermen
  • 13
  • 3
  • Not sure about function handles in _constant_ properties, but if you just want to save some functions why not write them as [`static`](https://uk.mathworks.com/help/matlab/matlab_oop/static-methods.html) methods? – Hoki Nov 04 '20 at 09:31
  • Since abstract functions are objects, I would like to access these objects without a method in between. But yeah I suppose using a static method can solve this. – RedGermen Nov 04 '20 at 15:37
  • 1
    You cannot access an _abstract_ object, you can only build an object which _inherit_ from them. This is a concept far different than your question. Back to your question, don't get stuck on a specific term (`method`, `function`, `property`). What you want your object to do is to perform calculations based on some input parameter and give out a result. This is the best use case for the `method` block in MATLAB class definition. (Other languages will allow you to define `function/method` as `property` but MATLAB is not designed that way). – Hoki Nov 04 '20 at 17:43
  • Also, the `static` classes and function/method in MATLAB do not require you to instantiate the object to access the method, so accessing these calculations can be done directly in one simple call to the method (one line of code). – Hoki Nov 04 '20 at 17:46
  • Ah sorry, my bad. I tried to say Anonymous Function not abstract function, I failed miserably, For example, I can call an Anonymous function inside another Anonymous function to create another abstract function. I want to be able to utilize this ability. – RedGermen Nov 05 '20 at 09:18

0 Answers0