Why is my code not plotting anything?

조회 수: 1 (최근 30일)
Anupam Verma
Anupam Verma 2021년 8월 19일
댓글: Walter Roberson 2021년 8월 19일
x = 1:0.1:10;
y=x.^2;
plot(x,y);
I wrote the above simple code, but when I save this code in a script, it doesn't work when I press the green run button. However if I type it in the command window, it runs fine. Can someone please help me with this. (I am on a Mac.)
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 8월 19일
It works for me on Mac, in the same release as you used.
But exactly what filename did you use when you saved it as a script ?

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

답변 (1개)

Star Strider
Star Strider 2021년 8월 19일
It is necessary to save the script as a .m file first, and the MATLAB Editor should have popped up the Save As window when you pressed the green Run arrow if you had not already saved that script. (It did just now when I attempted to do exactly what you describe, in R2021a.)
.
  댓글 수: 2
Image Analyst
Image Analyst 2021년 8월 19일
편집: Image Analyst 2021년 8월 19일
@Star Strider, do you have a mac? Because I did it on a Windows 10 system and it worked just fine, just as expected.
Star Strider
Star Strider 2021년 8월 19일
Win 10, latest updates.
When I copied it to a new script, then clicked on the green Run arrow, the Save As window popped up, telling me to save it first (with the default ‘Untitled.m’). Then it ran without error.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by