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?

1 vue (au cours des 30 derniers jours)
In function editor:
  1. function A = practice(x)
  2. A = sin(x);
In Command Window:
>> fplot('practice',[-10 10])
  2 commentaires
Matthew Tom
Matthew Tom le 14 Nov 2015
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.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 14 Nov 2015
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 commentaires
Matthew Tom
Matthew Tom le 14 Nov 2015
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!
Star Strider
Star Strider le 14 Nov 2015
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)'.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by