Input Argument is Undefined

1 view (last 30 days)
Juan Manuel Castro V.
Juan Manuel Castro V. on 25 Nov 2015
Commented: Image Analyst on 25 Nov 2015
Hello!
I am trying to make a procedure to compute the mean of a log of probabilities. I am a beginner in Matlab so I am having a bad time finding the error. I am sure is pretty easy, but please help me!
function lik = proc1(c,K,R,c_0)
X = trnd(K,R,1)+c_0; %Generates a random sample of X from Y and the true value c_0 of size R
P = tpdf(X-ones(size(X))*c,K); %Returns the prob. of each x.
lik = mean(log(P)); %Takes the mean of the log of the probabilities
It gives me the following error:
??? Input argument "K" is undefined.
Error in ==> proc1 at 3
X = trnd(K,R,1)+c_0; %Generates a random sample of X from Y and the true value c_0 of size R
>>
However, when I evaluate the function in the command window it works fine.
How do I stop getting this error?
  1 Comment
Image Analyst
Image Analyst on 25 Nov 2015
How did you call the function from your other function or script? Like, did you do something like this:
lik = proc1(1, 2, 33, 555)
or
c=41;
K=92;
c_0 = 2342;
lik = proc1(c,K,R,c_0)
or something similar? Somehow you MUST pass it arguments because you defined it such that it must. If the arguments are optional, then you can do it another way, with varargin, where you can detect input arguments and assign default values to any (or all) that are null (not supplied).

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!