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.
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)
Afficher commentaires plus anciens
Matthew Tom
le 14 Nov 2015
Commenté : Walter Roberson
le 15 Nov 2015
In function editor:
- function A = practice(x)
- A = sin(x);
In Command Window:
>> fplot('practice',[-10 10])
2 commentaires
Réponse acceptée
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
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)'.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!