access separate function file from handleclass
Mostrar comentarios más antiguos
Hi,
I'm trying to use separate function files to be accessed from a handleclass.
Here's the class that I defined, including two methods that are defined in separate function files (located in the @myclass directory).
classdef myclass <handle
properties
factor;
x;
y;
end
methods
me = myfactor(me)
out = myfactor2(x, factor)
function me = myclass(x)
me.x = x;
end
function me = setfactor(me, f)
me.factor = f;
end
function me = inclassfactor(me)
me.y = me.x.^me.factor;
end
function me = testfactor(me)
me = myfactor(me);
end
function me = testmyfactor2(me)
me.y = myfactor2(me.x, me.factor);
end
function me = testfeval(me)
me = feval('myfactor', me);
end
end
end
The functions defined are all the same (x.^factor).
I then run a small test:
X = [0 1 2 3];
test = myclass(X);
test.setfactor(2);
test.inclassfactor
test.setfactor(1);
test.testfactor;
test.setfactor(2);
test.testfeval;
test.setfactor(3);
test.testmyfactor2;
it gives an error for the last line of code, myfactor2 is an undefined function.
I know that I can use myfactor as a suitable 'workaround', but I would like to understand why myfactor2 is not recognized.
Can anyone explain to me what I'm missing/not understanding?
Thanks in advance,
Dagmar
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Whos en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!