Can no longer label axes in plots.

7 次查看(过去 30 天)
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