symbol from string [2]
조회 수: 9 (최근 30일)
이전 댓글 표시
I have already posted about this ( http://www.mathworks.it/matlabcentral/answers/7220-symbol-from-string )
a='name'
syms (a)
this code generates a symbol called 'name'. If I write a function, I don't know the string before I use it, so how can I use the symbol 'name' (like symbol) into the function?
i.e
function [A]=f(a)
a='name';
syms (a)
c=cos(name);
s=sin(name);
A=c+s;
In the output I want a symbolic expression A=cos(name) + sin(name).
Thank you a lot for you answer. Pietro Rossi
댓글 수: 0
채택된 답변
Walter Roberson
2011년 5월 11일
I would try
function [A]=f(a)
%a='name'; %I presume this will be passed in
syms (a)
c=cos(a);
s=sin(a);
A=c+s;
댓글 수: 3
Walter Roberson
2011년 5월 11일
Ah, in that case,
function [A]=f(a)
as = syms (a)
c=cos(as);
s=sin(as);
A=c+s;
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!