When I plot a function using the fplot command, for example sin(x), the fplot command keeps on displaying the linear graph y = x. How do I resolve this issue?

In function editor:
  1. function A = practice(x)
  2. A = sin(x);
In Command Window:
>> fplot('practice',[-10 10])

2 comentarios

Actually never mind, it worked. But how do I call a function from a function file rather than having to rewrite the function and the variable. Is there a setting on MATLAB that keeps printing out the graph y = x instead of sin(x)? It was originally working for me when I first started using MATLAB, and now I am not sure what happened.

Iniciar sesión para comentar.

 Respuesta aceptada

I did not run your code, but after looking at the fplot documentation, since your ‘practice’ function is an external function, try this:
fplot(@practice,[-10 10])

4 comentarios

Thank you for the assistance, but sadly it didn't work when I tried the command. The fplot command always takes the form of fplot('function name',[lower limit upper limit]). I think I might have selected a setting that uses y = x every time I use the fplot command, but the question is what setting did I accidentally select?
Are you using a very old MATLAB release such as MATLAB 4.2 ?
fun must be
  • The name of a function
  • A string with variable x that may be passed to eval, such as 'sin(x)', 'diric(x,10)', or '[sin(x),cos(x)]'
  • A function handle
Okay, now I figured out what happened. I forgot to open my path folder containing all of my scripts and files which is why it kept on printing out the same y = x graph. Thank you for your assistance. My question has been solved!
I went back and tried it, and the syntax I used in my Answer worked with your function, as it should, according to the way I read the documentation. I’m using R2015b. Are you using a different version?
It produces the linear graph you describe with the quoted 'practice' syntax, but the correct plot with the function handle @practice syntax. According to the documentation, the quote syntax only works with a string that can be passed to the eval function for evaluation, such as 'sin(x)'.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 14 de Nov. de 2015

Comentada:

el 15 de Nov. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by