Nested functions in a class - Call the function without including the class name as filename.function
5 views (last 30 days)
Hello MATLAB experts,
I defined a class with different functions that are called from external .m files but also call eachother reciprocally, that is the functions call other functions in the same class. As far as I could understand, I always have to use the call form classname.function to call a function from this class. However, I would rather avoid it for the function that are all in the same class in the same file (similarly to local functions), to make the code clearer.
function d = sum_scale_test(a,b)
c = a+b;
d = small_test.scale_test(c);
function b = scale_test(a)
Is there a way to skip the long call:
and just use
Maybe with some access option?
Thank you for the help!
Mitch Lautigar on 1 Jun 2022
Edited: per isakson on 3 Jun 2022
You can put subfunctions/nested functions below the Class call (after the end for classdef) and therefore have local functions for the class to reference. This will look like the following:
function obj = dosomething(obj)
%do stuff here