在 GUI MATLAB 中调用局部变量时出错
我收到此错误:
Error in ==> APP>pushbutton2_Callback at 109
img=imread(FileName)
当我尝试在 pushbutton2_Callback
中使用 FileName
时,我收到提到的错误
FileName
is variable in Pushbutton1_Callback
。
I'm getting this error:
Error in ==> APP>pushbutton2_Callback at 109
img=imread(FileName)
When I try to use FileName
in pushbutton2_Callback
I'm getting the error mentioned
FileName
is variable in pushbutton1_Callback
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将变量
FileName
从一个回调传递到另一个回调。为此,您可以将该变量分配给pushbutton1
的'UserData'
字段。pushbutton1_Callback
下的代码应类似于:接下来,您需要读入
pushbutton2_Callback
下的变量:如果您想检查结果,可以随时保留分号超出了线路的末端。
You need to pass the variable
FileName
from one callback to the other. To do this, you can assign the variable to the'UserData'
field ofpushbutton1
. Your code underpushbutton1_Callback
should look something like:Next, you need to read in the variable under your
pushbutton2_Callback
:If you want to check your results, you can always leave the semicolons off the end of the lines.
有一种通用方法可以使用 gui 存储数据,以便在回调之间使用。您可以将任意字段添加到handles对象,这样您就可以放入pushbutton1回调中。
第二行是样板代码,您需要将其放在任何更改handles结构中的值的回调的末尾。
现在您的所有回调都可以访问该文件名。在您的具体情况下,在回调 2 中,您当然
可以稍后在另一个函数中使用该图像,因此您也可以将其存储在句柄中
There's a general method to store data with your gui for use between callbacks. You can add arbitrary fields to the handles object, so you can put in your pushbutton1 callback
The second line is boilerplate code that you need to put at the end of any callback that changes values in the handles structure.
Now all of your callbacks will have access to the file name. In your specific case, in callback 2, you would have
Of course, you might want to use this image later on in another function, so you can store it in handles too