Can no longer label axes in plots.
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
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'
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.
Risposta accettata
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
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
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!