String scalar or character vector must have valid interpreter syntax?

조회 수: 15 (최근 30일)
Tobias Frederiksen
Tobias Frederiksen 2021년 12월 16일
편집: Nirupama 2024년 2월 26일
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
Stephen23
Stephen23 2021년 12월 16일
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 2021년 12월 16일
I think it is MATLAB R2020b. Should i update it?

댓글을 달려면 로그인하십시오.

답변 (1개)

Nirupama
Nirupama 2024년 2월 26일
편집: Nirupama 2024년 2월 26일
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!

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by