xlabel and ylabel errors
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
winfrida mwigilwa
le 17 Fév 2025
Commenté : Walter Roberson
le 17 Fév 2025
I have the following code:
x = linspace(-2*pi,2*pi,100);
y1 = sin(x);
y2 = cos(x);
figure
plot(x,y1,x,y2)
xlabel('-2\pi < x < 2\pi')
ylabel('Sine and Cosine Values')
when I run it brings the following error
Index exceeds the number of array elements. Index must not exceed 3.
Error in mfano (line 8)
ylabel('Sine and Cosine Values')
1 commentaire
Paul Bower
le 17 Fév 2025
Hi Winfrida, Just FYI ... I ran your code on version R2024b and it works fine.
Réponse acceptée
Star Strider
le 17 Fév 2025
This is instructive:
when I run it brings the following error
Index exceeds the number of array elements. Index must not exceed 3.
Error in mfano (line 8)
ylabel('Sine and Cosine Values')
Check to see if you have a variable named ‘ylabel’.
To do that, run this from a script or your Command Window —
which ylabel -all
You should only get results similar to these. If the first entry is:
ylabel is a variable.
you have identified the problem. The solution is to re-name the variable.
.
3 commentaires
Walter Roberson
le 17 Fév 2025
It is somewhat common to code, for example
ylabel = ('Sine and Cosine Values')
which creates a variable named ylabel instead of calling the function named ylabel
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Elementary Math dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!