str2sym error
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Giorgos Minas
el 21 de Feb. de 2024
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?
0 comentarios
Respuesta aceptada
Voss
el 21 de Feb. de 2024
I get a different error:
try
S = str2sym('force(t)')
catch e
disp(e.message);
end
Anyway, here's a workaround:
S = str2sym('forces(t)');
S = subs(S,'forces','force')
2 comentarios
Más respuestas (1)
Walter Roberson
el 21 de Feb. de 2024
Work around:
symfun('force(t)', sym('t'))
or
syms force(t)
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!