필터 지우기
필터 지우기

str2sym error

조회 수: 12 (최근 30일)
Giorgos Minas
Giorgos Minas 2024년 2월 21일
편집: Voss 2024년 2월 21일
When using the str2sym function for a particular string I get the following error.
>> str2sym('force(t)')
Error using str2sym
Unable to convert string to symbolic expression:
Invalid indexing or function definition. Indexing must follow MATLAB
indexing. Function arguments must be symbolic variables, and
function body must be sym expression.
There seems to be something special about the word “force” in Matlab because any misspelling of the word (e.g. str2sym('forcei(t)') ) and the error disappears.
It is essential to use the word "force" for the program I run and I cannot use another word.
This is reproduced in the online version of Matlab here https://matlab.mathworks.com, as well as my local Matlab 2023a.
Could you please help?

채택된 답변

Voss
Voss 2024년 2월 21일
I get a different error:
try
S = str2sym('force(t)')
catch e
disp(e.message);
end
Unable to convert string to symbolic expression: Undefined function 'force' for input arguments of type 'sym'.
Anyway, here's a workaround:
S = str2sym('forces(t)');
S = subs(S,'forces','force')
S = 
  댓글 수: 2
Giorgos Minas
Giorgos Minas 2024년 2월 21일
This seems to work. Thanks. Much appreciated.
Voss
Voss 2024년 2월 21일
편집: Voss 2024년 2월 21일
You're welcome! Any questions, let me know.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2024년 2월 21일
Work around:
symfun('force(t)', sym('t'))
or
syms force(t)

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by