如何获取局部变量? [英] How to retrieve local variables?

查看:129
本文介绍了如何获取局部变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从我在Matlab中运行的程序函数中检索局部变量?也就是说,我想从代码中检索变量,该变量不会出现在输出中.

Is it possible to retrieve a local variable from a programme-function i've run in matlab? i.e. i want to retrieve a variable from the code, which is not appeared in the outputs.

预先感谢

推荐答案

以下内容描述了添加到函数本身以使变量在本地范围之外可用的代码.当您无法更改功能时,从外部无需更改课程范围(这是正确的行为!).

The following describes code to add to the function itself to make the variable available outside the local scope. When you can't change the function, from the outside there is nothing to be done about changing the scope of course (which is intended, correct behaviour!!).

肮脏的方式:

global t
t=2.468;

  • 对于标量,字符串,简单值:使用

  • 任何其他变量,请使用分配:

  • Any other variable, use assignin:

    A=magic(20);
    assignin('base','A',A);
    

  • 正确的方法:

    • 调试
    • 期间进行检查
    • 如果您真的希望它们不在本地范围内,请将它们添加为输出变量!
    • Inspect them during debugging
    • If you really want them outside the local scope, add them as output variable!!

    这篇关于如何获取局部变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆