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:
  1. function A = practice(x)
  2. A = sin(x);
In Command Window:
>> fplot('practice',[-10 10])
  댓글 수: 2
Matthew Tom
Matthew Tom 2015년 11월 14일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
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
Matthew Tom
Matthew Tom 2015년 11월 14일
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 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개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by