Global symbolic variable definition
24 ビュー (過去 30 日間)
古いコメントを表示
Hi Dear Matlab users
I defined a variable in .M file and assigned a symbolic value to that variable.Then I defined a function and I want to use that variable in this function I wrote.
I tried to define that variable global but program declares it double default and when it tries to assign the symbolic equation to that variable; it can not convert sym to double. How can I solve this problem ?
Thank you
2 件のコメント
回答 (1 件)
Azzi Abdelmalek
2013 年 3 月 1 日
編集済み: Azzi Abdelmalek
2013 年 3 月 1 日
In windows command you should declare a as a sym global
syms a
global a
3 件のコメント
mohammad m
2016 年 12 月 17 日
編集済み: mohammad m
2016 年 12 月 17 日
hi in matlab 2013 i use like this but i get error that : undefined variable's. i want to use
syms x
global x
in my code, Then in my function in other mfile use this variable without syms in funcyion, like this
function a=f
f=x
end
but i get error, its not possible or my code is wrong? i don't want to use syms in my function, because it reduce speed.
Walter Roberson
2016 年 12 月 17 日
global x %has to go before the syms
syms x
and then in your function
function a=f
global x
a=x
end
If you are trying to avoid the syms call because of the overhead, but want to use the symbol, then you should consider passing it to your function instead of using global. global is the slowest method of accessing variables. You should consider parameterizing your functions to include the symbol that you want to work with.
参考
カテゴリ
Help Center および File Exchange で Symbolic Variables, Expressions, Functions, and Preferences についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!