symfun to sym conversion error only in a Function (not Script)

조회 수: 5 (최근 30일)
amin ya
amin ya 2019년 3월 13일
댓글: amin ya 2019년 3월 14일
When I use the following code as a script it works without any error.
% function [A]=myFun()
syms t real %time
syms w(t)
w=formula(w);
% I use this to convert symFun to sym
% so I can access to "A" matrix elements which uses w
A=[sin(w);cos(w)]; % "A" matrix is now a 2*1 sym instead of a 1*1 symfun
% end
But when I want to use the code inside a function which passes A matrix as an output, and I call the function I get this error:
"w" previously appeared to be
used as a function or command,
conflicting with its use here as
the name of a variable.
A possible cause of this error is
that you forgot to initialize the
variable, or you have initialized
it implicitly using load or eval.
  댓글 수: 2
Walter Roberson
Walter Roberson 2019년 3월 13일
Try using W=formula(w) and referring to W afterwards -- so that you are not overwriting function w with non-function w.
amin ya
amin ya 2019년 3월 14일
Thank you, it works! It was as easy as changing the name.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by