Danny
Danny

Reputation: 203

How to use `fplot` with a function that has more than one argument?

I have a function,which is saved as .m file, called: mlekv which takes two arguments 'alpha', 'random' where 'random' is a vector of random numbers.Here it is:

function y = mlekv(alpha,random)

mean = sum(random)/size(random,2)
geomean = nthroot(prod(random),size(random,2))

y = log(alpha) - log(mean) - psi(alpha) + log(geomean)

Now i would like to plot this function in an intervall [0.4,5]. I tried to create a handle for my function:

fh = @mlekv;      %name of function
fplot(fh,[0.4,5]) 

The problem is that i need to pass two arguments 'alpha' and 'random', I would like 'random' to be fixed as Matlab plots the function in the interval [0.4,5].I don't know how to accomplish this can i get some advice?

Upvotes: 0

Views: 66

Answers (1)

A. Donda
A. Donda

Reputation: 8477

Define fh as a handle to a new function:

random_fixed = rand;    % or whatever kind of random numbers are needed
fh = @(alpha) mlekv(alpha, random_fixed);
fplot(fh,[0.4,5]) 

Upvotes: 1

Related Questions