MATLAB tutorials:MATLAB Fundamentals may have a wrong answer

Visualizing Data in 2D and 3D > Customized Annotations > (3/3) Adding Specialized Annotations
Task 2
The offical answer is
ylabel(yTxt)
But I think the right answer is
clear ylabel
ylabel(yTxt)
Although I think "clear ylabel" should not be necessary.

 채택된 답변

Hiro Yoshino
Hiro Yoshino 2023년 5월 26일
편집: Hiro Yoshino 2023년 5월 26일
I do not think you are right.
ylabel (find the link here) is not a variable but a command. So you do not need to clear it unless you have a variable named "ylabel".
last = 4;
r = 0:0.1:last;
A = pi*r.^2;
plot(r,A)
xlabel("r");
yTxt = ["Area";"\pi r^2"];
ylabel("Hello");

댓글 수: 2

I am so sorry. You are right, and I might do some wrong operations to get this wrong conslusion.
DGM
DGM 2023년 5월 26일
편집: DGM 2023년 5월 26일
You will find that a number of answers on the topic do mention clearing ylabel or xlabel.
The reason is simply that it's very common that users accidentally create a variable by the same name and then wonder why xlabel() and ylabel() don't work. When that happens, one has to clear the variable in order to use the function of the same name.
Just like size(), image() and title(), xlabel() is one of many functions with a name that makes a very obvious and convenient variable name. These things happen.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

릴리스

R2023a

태그

질문:

2023년 5월 26일

편집:

DGM
2023년 5월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by