MATLAB Answers

what is this error "error updating text"

조회 수: 15(최근 30일)
jacob booth
jacob booth 2021년 7월 28일
댓글: jacob booth 2021년 7월 28일
i keep gettin an error i have not seen before
"Warning error updating text string scalar or character bector must have valid interpreter syntax"
below is the code
x=(1:15); % x
y=[0.35 0.4 0.52 0.58 0.46 0.74 0.68 0.82 1.03 1.17 1.81 2.01 2.63 3.29 4]; % y
P=polyfit(x,log(y),1);
A=exp(P(2))
B=(P(1))
y_fit=a*exp(b*x);
figure
plot(x,y,'r*')
xlabel('x')
ylabel('y and y__fit')
grid on
hold on
plot(x,y_fit,'-b')
legend('Original data (y)','Fitted data (y__fit)')
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2021년 7월 28일
Add "clear all" as the first line of your code, run it again, debug it and paste the error that you couldn't resolve.

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

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 7월 28일
By default, labels and legends (among other things) apply a tex interpreter to their text. The '_' is used to indicate a subscript.
In your text, you use a double underscore: 'y__fit'. The error is telling you that MATLAB does not know how to interpret this. If you do not want it to do anything, change your code to set the corresponding interpreters to 'none'.
x=(1:15); % x
y=[0.35 0.4 0.52 0.58 0.46 0.74 0.68 0.82 1.03 1.17 1.81 2.01 2.63 3.29 4]; % y
P=polyfit(x,log(y),1);
a=exp(P(2))
a = 0.2555
b=(P(1))
b = 0.1722
y_fit=a*exp(b*x);
figure
plot(x,y,'r*')
xlabel('x')
ylabel('y and y__fit','Interpreter',"none")
grid on
hold on
plot(x,y_fit,'-b')
legend('Original data (y)','Fitted data (y__fit)','Interpreter',"none")
You can read more about legend interpreters here and ylabel interpreters here.
  댓글 수: 1
jacob booth
jacob booth 2021년 7월 28일
thank you it worked perfectly

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

추가 답변(0개)

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by