Undefined function 's' for input arguments of type 'double'

조회 수: 1 (최근 30일)
Maciej Satora
Maciej Satora 2017년 9월 2일
댓글: Madhusudan Kulkarni 2018년 2월 25일
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 :)

답변 (3개)

Henry Giddens
Henry Giddens 2017년 9월 2일
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

Steven Lord
Steven Lord 2017년 9월 2일
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.

swati paliwal
swati paliwal 2018년 2월 14일
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
Madhusudan Kulkarni
Madhusudan Kulkarni 2018년 2월 25일
create your own thread for same problem. Many people may see and answer. Type program properly. No end statement in given program.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by