Can no longer label axes in plots.

조회 수: 10 (최근 30일)
James
James 2023년 10월 17일
댓글: James 2023년 10월 17일
Not sure what has happened, but drawing plots on Matlab I am now no longer able to name the axes in the figures. I have updated to Matlab 2023b to see whether this would repair it - it did not.
Even a simple code does not work,
x = [1 2 3];
y = [1 2 3];
figure('Name',"Test", 'NumberTitle','off')
plot(x,y)
xlabel = 'x';
ylabel = 'y';
this produces:
Is there a way of accidentally turning the xlabel and ylabel commands off?
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 10월 17일
"Even a simple code does not work,"
The code is working as you have wrote it to be. You have assigned the variables named xlabel and ylabel the values 'x' and 'y', and they have been defined so; as you can see below.
The fact that you used the wrong sytax, does not mean it does not work.
xlabel = 'x'
xlabel = 'x'
ylabel = 'y'
ylabel = 'y'
And in doing so, you have overwritten the functions xlabel and ylabel. And when you use xlabel('x') it gives an error.
This also points to the fact that one should not use built-in functions as variable names.
James
James 2023년 10월 17일
Can you rewrite that in a less passive aggressive tone? It reeks of fear and a masking of insecurity.

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

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 10월 17일
Edit your code in this way:
x = [1 2 3];
y = [1 2 3];
figure('Name',"Test", 'NumberTitle','off')
plot(x,y)
xlabel('x')
ylabel('y')
% Alt. way for later versions of MATLAB:
x = [1 2 3];
y = [1 2 3];
figure('Name',"Test", 'NumberTitle','off')
plot(x,y)
xlabel 'x'
ylabel 'y'
  댓글 수: 2
James
James 2023년 10월 17일
The first option gives the error message:
Error in untitled (line 5)
xlabel('x')
The second option works for me, I must have previously applied updates making the previous methods obsolete.
Dyuman Joshi
Dyuman Joshi 2023년 10월 17일
"I must have previously applied updates making the previous methods obsolete."
Yes.
You have over-written the built-in functions, thus they are not working as intended.
Remove the assignment you have done by running in your command window -
clear xlabel ylabel
then you can use
xlabel('x')
ylabel('y')
If you are unsure as to what the correct syntax for a function is, you can always refer to the documentation
help xlabel
XLABEL X-axis label. XLABEL('text') adds text beside the X-axis on the current axis. XLABEL('text','Property1',PropertyValue1,'Property2',PropertyValue2,...) sets the values of the specified properties of the xlabel. XLABEL(AX,...) adds the xlabel to the specified axes. H = XLABEL(...) returns the handle to the text object used as the label. See also YLABEL, ZLABEL, TITLE, SUBTITLE, TEXT. Documentation for xlabel doc xlabel

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by