>> fplot(fh,[-2 4])
??? Undefined function or variable "e".
Error in ==> myfun at 3
Y(:,2) = e(:).^x;
Error in ==> fplot at 102
x = xmin; y = feval(fun,x,args{4:end});
I tried to plot two function using this m file.
function Y = myfun(x)
Y(:,1) = 3*x;
Y(:,2) = e(:).^x;
As Donnie mentioned in their comment, the variable
eis undefined in your m-file.If you have defined
eelsewhere, you have to pass it tomyfunso that the function knows its value. Sincefplotdoes not accept plotting functions with more than one input value, you need to pass it an anonymous function.First, you need to change the definition of
myfunto includeeas input:Then, you create your function handle fh like this (fh still only takes one input, Matlab uses the value of
eas it was defined in the workspace at the time you create the function handle):Finally, you can call fplot like you used to