Error using sym>convertChar
이전 댓글 표시
Error using sym>convertChar
Character vectors and strings in the first argument can only specify a variable or number. To evaluate character vectors and strings
representing symbolic expressions, use 'str2sym'.
Error in sym>tomupad (line 1608)
S = convertChar(x);
Error in sym (line 400)
S.s = tomupad(x);
Error in sym/privResolveArgs (line 1180)
argout{k} = sym(arg);
Error in sym/diff (line 29)
args = privResolveArgs(S, invars{:});
Error in NEWTONRAPHSON/STARTButtonPushed (line 39)
df = diff(app.fun,x);
Error in matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)
newCallback = @(source, event)executeCallback(appdesigner.internal.service.AppManagementService.instance(), ...
Error while evaluating Button PrivateButtonPushedFcn.
HOW DO I SOLVE THIS PROBLEM
댓글 수: 15
KSSV
2022년 5월 27일
Show us your code.
CHUNG SI HAO
2022년 5월 27일
Walter Roberson
2022년 5월 27일
eval() of a symbolic expression such as df has undefined results. You should never eval() anything symbolic. Use subs() instead.
CHUNG SI HAO
2022년 5월 27일
Walter Roberson
2022년 5월 27일
df = diff(str2sym(app.fun),x);
CHUNG SI HAO
2022년 5월 27일
Walter Roberson
2022년 5월 27일
app.dfdxEditField.Value = char(df) ;
CHUNG SI HAO
2022년 5월 27일
Walter Roberson
2022년 5월 27일
Change line 40
app.dfdxEditField.value = char(df) ;
to become
app.dfdxEditField.Value = char(df) ;
Notice value with lower case becomes Value with upper case
CHUNG SI HAO
2022년 5월 27일
Walter Roberson
2022년 5월 27일
change
x = xold;
Function = eval(app.fun);
Derivative = eval(df);
to
Function = double(subs(str2sym(app.fun),x,xold));
Derivative = double(subs(df, x, xold)) ;
Walter Roberson
2022년 5월 27일
Have you considered how much easier it would be if you had stored str2sym of the function in app.fun instead of converting the text to symbolic all the time? And have you considered how much easier it would be to use matlabFunction?
CHUNG SI HAO
2022년 5월 27일
Walter Roberson
2022년 5월 27일
At some point you have code similar to
app.fun = app.Editfield1.Value;
You would change that to
app.fun = str2sym(app.Editfield1.Value);
CHUNG SI HAO
2022년 5월 28일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Operations on Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!