Can no longer label axes in plots.

7 visualizzazioni (ultimi 30 giorni)
James
James il 17 Ott 2023
Commentato: James il 17 Ott 2023
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 Commenti
Dyuman Joshi
Dyuman Joshi il 17 Ott 2023
"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 il 17 Ott 2023
Can you rewrite that in a less passive aggressive tone? It reeks of fear and a masking of insecurity.

Accedi per commentare.

Risposta accettata

Sulaymon Eshkabilov
Sulaymon Eshkabilov il 17 Ott 2023
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 Commenti
James
James il 17 Ott 2023
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 il 17 Ott 2023
"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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Mathematics in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by