0
>> 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;
1
  • 1
    You appear to be using the vector e(:) without actually defining it. Commented May 29, 2010 at 18:37

1 Answer 1

1

As Donnie mentioned in their comment, the variable e is undefined in your m-file.

If you have defined e elsewhere, you have to pass it to myfun so that the function knows its value. Since fplot does 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 myfun to include e as input:

function Y = myfun(x,e)
Y(:,1) = 3*x;
Y(:,2) = e(:).^x;

Then, you create your function handle fh like this (fh still only takes one input, Matlab uses the value of e as it was defined in the workspace at the time you create the function handle):

fh = @(x)(myfun(x,e))

Finally, you can call fplot like you used to

fplot(fh,[-2 4])
Sign up to request clarification or add additional context in comments.

2 Comments

problem solved . But Can some one tell how to get root visually on the graph.?
In the figure window, click on the data cursor and read the x-value of the root from the datatip, as demonstrated here: mathworks.com/access/helpdesk/help/techdoc/creating_plots/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.