Effacer les filtres
Effacer les filtres

String scalar or character vector must have valid interpreter syntax?

8 vues (au cours des 30 derniers jours)
Tobias Frederiksen
Tobias Frederiksen le 16 Déc 2021
Modifié(e) : Nirupama le 26 Fév 2024
Hello.
I am trying to make a legend for a plot, but i get the error 'String scalar or character vector must have valid interpreter syntax'. The code is showed below.
m = 4;
legend(['Lagrange, {\itp}_{' num2str(m) '}({\itx})'],'Interpolated points','Discrete points','location','best') ;
Can someone tell me what to do? :-)
  2 commentaires
Stephen23
Stephen23 le 16 Déc 2021
What MATLAB version are you using?
plot(1:5,rand(5,3))
m = 4;
t = ['Lagrange, {\itp}_{' num2str(m) '}({\itx})']
t = 'Lagrange, {\itp}_{4}({\itx})'
legend(t,'Interpolated points','Discrete points','location','best')
Tobias Frederiksen
Tobias Frederiksen le 16 Déc 2021
I think it is MATLAB R2020b. Should i update it?

Connectez-vous pour commenter.

Réponses (1)

Nirupama
Nirupama le 26 Fév 2024
Modifié(e) : Nirupama le 26 Fév 2024
I ran the following lines of code in MATLAB R2020b and did it not throw any error (as you mentioned in the comments that you were using MATLAB R2020b):
plot(1:5,rand(5,3))
m = 4;
legend(['Lagrange, {\itp}_{' num2str(m) '}({\itx})'],'Interpolated points','Discrete points','location','best')
I do not think it an issue related to MATLAB R2020b. I would recommend you to clear the workspace and command window and retry executing the above lines of code.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by