W = evalin('caller','who global') returns an error
显示 更早的评论
The command
evalin('caller','who global')
correctly returns the global variables in the caller workspace, but
W = evalin('caller','who global')
returns the error message
Error: illegal use of the reserved keyword global
Yet the syntax of the line that throws the error is consistent with the prescribed use of evalin. Is this a bug? What's the workaround? Thanks
3 个评论
Steven Lord
2020-6-10
That code is basically equivalent to running this code in the caller's workspace.
W = who global
You can't use command form when you want to get an output argument from the function that you're calling.
Walter has shown you one way to perform this call. But in general, both evalin and global are discouraged. Can you say a little more about why your function is reaching up into its caller's workspace and why you're using global variables? We may be able to offer some alternatives.
Leo Simon
2020-6-10
Walter Roberson
2020-6-10
I would disagree on that checking. You want to encourage migration to passing variables as parameters, to reduce the reliance on global variables.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 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!