在MATLAB GUI使得通用变量 [英] Making universal variables in MATLAB GUI

查看:347
本文介绍了在MATLAB GUI使得通用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点新MATLAB和我做一些实验的学校项目。

I'm kind of new to MATLAB and I'm doing some experiments for a school project.

我要的是有3个按钮,当你无论是前两个preSS,加起来比一的变量(一个变量为每个按钮)的GUI,而当你preSS第三按钮,它与来自第一两个按钮变量的东西。

What I want is a GUI with 3 buttons, when you press either of the first two, it adds up to one on a variable (one variable for each button), and when you press the third button, it does something with the variables from the first two buttons.

我用引导和拖放按钮,然后我修改的功能。

I used "guide" and dragged and dropped the buttons, and then I modified the functions.

但我意识到,我的变量只对按钮的功能里面,因此,如果我初始化他们,他们会重新开始,每次我preSS的按钮,也没有办法为我的第三个按钮就知道价值在第2位。

But I realized that my variables only exist inside the function for the button, so if I initialize them they would restart everytime I press the button, and also there is no way for my third button to know the value of the first two.

有没有办法使这个变量总是present?或者从一个函数传递到另一个?

Is there a way to make this variables always present? Or pass them from a function to another?

我的code这是由引导刚刚生成自动code,具有V1 = V1 + 1;在第一个按钮回调函数和v2 = V2 + 1中的第二个,并且在第三DISP(V1)DISP(v2)的

My code it's just the automatic code generated by "guide", with a v1 = v1+1; in the first button callback function and v2 = v2+1 in the second one, and disp(v1) disp(v2) in the third.

我希望你明白我的意思,我不是以英语为母语所以......

I hope you understand what I mean, I'm not a native english speaker so...

总之,非常感谢,希望它的东西很容易解决。

Anyway, thanks a lot, hope it's something easy to fix.

推荐答案

下面是不是最好的做法对大型复杂的程序,但对于一些简单的像你正在试图做的,它听起来就像全局变量将是完美的。说 X 以Z 是变量你想要功能之间共享。在添加使用它们每一个功能的开始之后,他们都将有机会获得相同的值。

The following is not the best practice for large complicated programs, but for something simple like what you're trying to do it sounds like global variables would be perfect. Say that X, Y, and Z are the variables you want to share between functions. Add the following at the beginning of every function that uses them, and they will all have access to the same values.

global X Y Z

这篇关于在MATLAB GUI使得通用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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