functions with obj as input not work

this is my class
classdef ServoSys
%UNTITLED2 Summary of this class goes here
% Detailed explanation goes here
properties
A=[0]
B=[0]
C=[0]
D=[0]
E=[0]
e
ts
end
methods
%__________________________________________
function [Ac,Bc,Cc,Dc]=CanonicaC(obj)
[numtf,dentf]=ss2tf(obj.A,obj.B,obj.C,obj.D);
Tf1=tf(numtf,dentf)
Ac=[zeros(length(dentf)-1)]
d=0;
for c=1:1:length(dentf)-1
for f=1:1:length(dentf)-1
if c==f-1
Ac(c,f)=1;
end
if c==length(dentf)-1
Ac(c,f)=dentf(length(dentf)-d)
d=d+1
end
end
end
end
%_______________________________
function [K] = MatrizW(obj)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
Sc=[obj.B obj.A*obj.B];
Qo=[obj.C;obj.C*obj.A];
if det(Sc)==0
disp('No controlable')
else
disp('Controlable')
end
if(det(Qo)==0)
disp('No Observable')
else
disp('Observable')
end
[numtf1,dentf1]=ss2tf(obj.A,obj.B,obj.C,obj.D);
Tf1=tf(numtf1,dentf1);
Wn=4/obj.e*obj.ts;
Bds=[1 2*obj.e*Wn Wn^2]
%Matriz de peso
p=1;
dentf1
for c=1:1:length(dentf1)-1
for f=1:1:length(dentf1)-1
fprintf(1,'ingrese el coef de la fila %i',c)
fprintf(1,' y columna %i',f)
W(c,f)=input('=');
end
end
%length(dentf1)
T=Sc*W
for a=1:1:length(dentf1)-1
K(a)=Bds(a+1)-dentf1(a+1)
end
K=K*T
end
%-------------------------------------
%________________________________
end
end
when i run it the method CanonicaC(MR) (where MR is an object of the class),displayed this
Undefined function 'CanonicaC' for input arguments of type 'ServoSys'.
srry for my english

8 Kommentare

Cedric
Cedric am 9 Aug. 2015
Bearbeitet: Cedric am 9 Aug. 2015
I've seen many times MATLAB somehow crash internally and generate an inaccurate error message when dealing with faulty OOP code.
If you correct the first line within CanonicaC and change
[numtf1,dentf1]= ..
for
[numtf,dentf]= ...
Is it working? If not, how do you create the object, and is the following working: (?)
MR.CanonicaC() ;
Jherson Castaño
Jherson Castaño am 9 Aug. 2015
Bearbeitet: Jherson Castaño am 9 Aug. 2015
Thanks, I saw I corrected that mistake but still does not work :(
this my obj
MR =
ServoSys with properties:
A: [2x2 double]
B: [2x1 double]
C: [1 0]
D: 0
E: [2x1 double]
e: 0.8000
ts: 2
>>
for MR.CanonicaC()
>> MR.CanonicaC()
No appropriate method, property, or field CanonicaC for class ServoSys.
Did you restart your MATLAB since you started these tests? As mentioned sometimes my MATLAB becomes erratic for a moment, and ends up crashing, when I am debugging OOP code, so my first move when something makes no sense, is to restart MATLAB.
If it still doesn't work, see what you get when you evaluate
methods( MR )
and
mc = metaclass( MR ) ;
(then see what information mc can provide you). What version of MATLAB are you using by the way? Maybe the fact that you have no constructor is not supported by your version.
per isakson
per isakson am 9 Aug. 2015
Bearbeitet: per isakson am 9 Aug. 2015
Run methods(MR). Do you get this output?
>> methods( MR )
Methods for class ServoSys:
CanonicaC MatrizW ServoSys
Jherson Castaño
Jherson Castaño am 9 Aug. 2015
thank you very much, it was enough to restart and now works
Cedric
Cedric am 9 Aug. 2015
Bearbeitet: Cedric am 9 Aug. 2015
Ok great! There is something wrong with MATLAB and OOP.. I get a few crashes per week when I am debugging classes, and it almost always starts with erratic behaviors from MATLAB, before fully crashing.
per isakson
per isakson am 9 Aug. 2015
Cedric, I think you are right. However, I have failed to demonstrate it in a reproducible way, which is needed to report the "issue(s)".
Cedric
Cedric am 9 Aug. 2015
Bearbeitet: Cedric am 10 Aug. 2015
Hi Per, I report the issue a good half of the times using the crash report, but it is generally impossible to provide a description of what specifically lead to the crash. The typical situation is that I have used the debugger in objects that involve overloads of SUBASGn/SUBSREF, and/or accessors of some sort. Then, sometimes minutes later when I am doing something else (e.g. answering a forum question), I observe an erratic behavior (often related to variables/memory, e.g. undefined variable that I had just defined, or undefined argument in a function call that I had defined), I press on ctrl-s for saving what I am doing, and it crashes at this moment (it saves well though).
Somehow it reminds me the delayed segmentation fault situation when I was programming in C in the 90's, before I started using tools like Electric Fence.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Steven Lord
Steven Lord am 10 Aug. 2015

1 Stimme

Did you construct the object and then modify the class to add the method definition? In release R2014b we improved the object workflow by eliminating the need for you to clear the class or previous instances when you modify the definition while instances exist (see the Language and Programming section of the Release Notes for MATLAB release R2014b) but if you're using an earlier release you would need to clear the class for the new method to be recognized.
Walter Roberson
Walter Roberson am 9 Aug. 2015

0 Stimmen

Your method is named CanonicaC but you are trying to invoke CanoicaC which is missing the second 'n'

1 Kommentar

Thanks, but that was a mistake on my writing
the problem persists
>> CanonicaC(MR)
Undefined function 'CanonicaC' for input arguments of type 'ServoSys'.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Function Creation finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 9 Aug. 2015

Bearbeitet:

am 10 Aug. 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by