Undefined function 's' for input arguments of type 'double'
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I am writing class and my methods. And I've got trouble calling the function r. When I write:
- obj = BasicClass;
- obj.Value = 1;
for example. And then I want to call the function by:
- answer = x(obj)
I got warning: Undefined function 's' for input arguments of type 'double'. Any ideas how could I repair it to achieve this reference in the function x? A reference that calls two other functions in the third one?
classdef BasicClass
properties
Value
end
methods
function [Result] = r (myobj)
Result = recurseComputeR(myobj.Value);
end
function [eindruck] = s (myobj)
eindruck = ComputeS(myobj.Value);
end
function [deltaf] = x (myobj)
deltaf = ComputeDeltaF(myobj.Value);
end
end
end
function deltaf = ComputeDeltaF(myobj)
deltaf = 0.0001 * (1000000000*s(myobj)+500000000*r(myobj));
end
function eindruck = ComputeS(myobjValue)
eindruck = myobjValue*0.000001;
end
function Result = recurseComputeR(myobjValue)
if myobjValue > 0
Result = recurseComputeR(myobjValue-1)*1000+2/1000000000000;
else
Result = 2/1000000000000;
end
end
Thank You very much in advance :)
0 Kommentare
Antworten (3)
Henry Giddens
am 2 Sep. 2017
Your function computeDeltaF expects the object as the input, not the property value
Change the following line:
function [deltaf] = x (myobj)
deltaf = ComputeDeltaF(myobj);
end
0 Kommentare
Steven Lord
am 2 Sep. 2017
A method of a class must accept an instance of the class as one of its inputs, unless it's a Static method. A class function, defined after the classdef block but in the same file, can accept an instance of the class but more commonly accepts just some data.
If a function needs to call a method on an instance of the class, the function probably should be a public method (if you need/want it to be accessible by code outside the class definition), a private method (if it doesn't need to be accessible by code outside the class definition), or a class function that accepts an instance of the object.
So let's look at the functions associated with your class.
function [Result] = r (myobj)
Result = recurseComputeR(myobj.Value);
end
Accepts an instance of the class, intended to be called by users of your class. Currently defined as a method, which I feel is correct.
function [eindruck] = s (myobj)
eindruck = ComputeS(myobj.Value);
end
Ditto what I said for your r method.
function [deltaf] = x (myobj)
deltaf = ComputeDeltaF(myobj.Value);
end
Ditto what I said for r and s.
function deltaf = ComputeDeltaF(myobj)
deltaf = 0.0001 * (1000000000*s(myobj)+500000000*r(myobj));
end
Currently defined as a class function. This calls methods on the class itself (s and r). I would make this either a private method or a class function into which you pass the object, not just one of the object's properties. Search the documentation for "class attributes" to learn how to make this into a private method if that's the approach you choose.
function eindruck = ComputeS(myobjValue)
eindruck = myobjValue*0.000001;
end
Currently defined as a class function. This only needs the value of one of the object's properties, so it seems appropriate as a class function.
function Result = recurseComputeR(myobjValue)
if myobjValue > 0
Result = recurseComputeR(myobjValue-1)*1000+2/1000000000000;
else
Result = 2/1000000000000;
end
end
Currently defined as a class function. Doesn't need to use the object, just one of its property values that is passed into it by its caller. Appropriate as a class function.
0 Kommentare
swati paliwal
am 14 Feb. 2018
vrxmf=zeros(rowmx,6); rowmx=1000; nrow=1; %...............printing in to file............. for n1=1:nrow-1; fid1=fopen('C:\Users\hp\Documents\MATLAB\ss1.dat'); fopen(fid1); fprintf(fid1,'%10.6f\t%10.6f\t%10.6f\t%7.4e\t%10.6f\t%10.6f\t\n',...... vrxmf1(n1,1),vrxmf1(n1,2), vrxmf1(n1,3), vrxmf1(n1,4), vrxmf1(n1,5),vrxmf1(n1,6));
Undefined function 'vrxmf1' for input arguments of type 'double'. Error in newton>fit_fun (line 435) fprintf(fid1,'%10.6f\t%10.6f\t%10.6f\t%7.4e\t%10.6f\t%10.6f\t\n',...... vrxmf1(n1,1),vrxmf1(n1,2), vrxmf1(n1,3), vrxmf1(n1,4), vrxmf1(n1,5),vrxmf1(n1,6)); How can i eliminate this error
1 Kommentar
Madhusudan Kulkarni
am 25 Feb. 2018
create your own thread for same problem. Many people may see and answer. Type program properly. No end statement in given program.
Siehe auch
Kategorien
Mehr zu Construct and Work with Object Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!