Not able to use function handles in MATLAB 2006b version.
1 回表示 (過去 30 日間)
古いコメントを表示
At the time of debugging function handles are working properly but when run complete program it fails. I am not able to find out cause behind that. Please reply.
Thanks & Regards, Kishor Dongare.
2 件のコメント
回答 (3 件)
Paulo Silva
2011 年 7 月 29 日
Not enough info, from MATLAB 2006b documentation I see that it supports function handles, please provide more details like the error that MATLAB gives and a sample of the code.
7 件のコメント
Walter Roberson
2011 年 10 月 12 日
Jan does not like to be sent email on such matters.
I do not have 2006b, but I am pretty good at analyzing errors *when I am told what the error is*. "it fails" is not enough description to go on.
Walter Roberson
2011 年 10 月 12 日
Do not use plain arrays to store function handles. Use cell arrays. Otherwise, your line
assignin('caller','level1_function',function_handle.handles(1));
invokes the function handle stored in function_handle.handles, passing it an argument of 1, and that is in a context where an output value is expected to satisfy the assignin(). If you were using cell arrays the line would be
assignin('caller','level1_function',function_handle.handles{1});
which would not invoke the function function handle.
Fangjun Jiang
2011 年 10 月 12 日
The code runs without error if you fix:
missing global definition in function Handles()
duplicated function SUB_GetFuncHandle()
8 件のコメント
Walter Roberson
2011 年 10 月 12 日
You have an 'end' statement in your main() routine. The JIT is allowed, in such a case, to assume that no variables will be "poofed into existence". You violate that assumption, so MATLAB is allowed to just not know about the poofed variables, and is allowed to operate corruptly if it encounters such a variable.
Before assigning a variable in a function workspace via assignin() or evalin() or load(), you should initialize the variable. You can initialize to anything at present, but better for potential future optimizations would be if you were to assign something of the same class as it will eventually become.
参考
カテゴリ
Help Center および File Exchange で Scope Variables and Generate Names についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!