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 (최근 30일)
이전 댓글 표시
In function editor:
- function A = practice(x)
- A = sin(x);
In Command Window:
>> fplot('practice',[-10 10])
댓글 수: 2
채택된 답변
Star Strider
2015년 11월 14일
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
Star Strider
2015년 11월 14일
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)'.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!