Can no longer label axes in plots.

7 ビュー (過去 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 Center および File ExchangeMathematics についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by