使MatlabGUI单选按钮作为图形可见性开关
我正在为我的一个脚本开发MatlabGUI。我的脚本有一个开始按钮,在这个按钮下我调用函数来解方程。我有三位数。因此,到目前为止,我的GUI运行良好。发生的情况是,当用户在给出所需输入后单击“开始”时,会一个接一个地弹出3个数字,我已经指定了保存这些数字的位置。当循环小的时候看起来不错,但是当循环大的时候,计算时间会增加,所以弹出的数字会让用户恼火,因为用户什么都做不了 我想在GUI中引入一个单选按钮,它将禁用图形的可见性。 我尝试了figure('Visible','off'),效果很好,但现在我想让它与单选按钮链接 单选按钮回调为:使MatlabGUI单选按钮作为图形可见性开关,matlab,Matlab,我正在为我的一个脚本开发MatlabGUI。我的脚本有一个开始按钮,在这个按钮下我调用函数来解方程。我有三位数。因此,到目前为止,我的GUI运行良好。发生的情况是,当用户在给出所需输入后单击“开始”时,会一个接一个地弹出3个数字,我已经指定了保存这些数字的位置。当循环小的时候看起来不错,但是当循环大的时候,计算时间会增加,所以弹出的数字会让用户恼火,因为用户什么都做不了 我想在GUI中引入一个单选按钮,它将禁用图形的可见性。 我尝试了figure('Visible','off'),效果很好,但现
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject handle to checkbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox2
有谁能帮我确定谁来设置代码,使此单选按钮在按钮中打开/关闭图形的可见性:
function Start_Callback(hObject, eventdata, handles)
% hObject handle to Start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
等待您的帮助。在您的
Start\u回调中
检查复选框/单选按钮的状态,并创建一个新变量供以后使用:
if get(handles.checkbox2, 'Value')
Visibility = 'on';
else
Visibility = 'off';
end
现在创建您的数字:
figure('Visible', Visibility)
根据
可见性
的值,它们将在开始\u回调中可见或不可见
检查复选框/单选按钮的状态,并创建一个新变量供以后使用:
if get(handles.checkbox2, 'Value')
Visibility = 'on';
else
Visibility = 'off';
end
现在创建您的数字:
figure('Visible', Visibility)
取决于
可见性的值
它们是否可见我假设您的主要问题是设置所有三个图形的可见性。对于设置特定地物的可见性,最好的选择是保持该地物的控制柄 我建议在打开新地物时保留地物句柄:
h1=图;%打开新图形,并将图形句柄存储在h1中
h2=图;%打开新图形,并将图形句柄存储在h2中
h3=图;%打开新图形,并将图形句柄存储在h3中
我认为在GUIOpeningFcg
函数中创建(打开)图形的正确位置
使用向导工具创建新GUI时,Matlab生成以下代码:
function guiname_OpeningFcg(hObject, evevntdata, handles, varargin)
...
handles.output = hObject;
guidata(hObject, handles);
...
在代码行guidata之后(hObject,handles)代码>,您可以创建数字。
将图形句柄存储在handles
结构中,以便以后使用:
function guiname_OpeningFcg(hObject, evevntdata, handles, varargin)
...
handles.output = hObject;
guidata(hObject, handles);
h1 = figure; %Open first figure, and store figure handle in h1
h2 = figure; %Open second figure, and store figure handle in h2
h3 = figure; %Open third figure, and store figure handle in h3
handles.h1 = h1; %Store handle to first figure.
handles.h2 = h2; %Store handle to second figure.
handles.h2 = h2; %Store handle to third figure.
在回调函数中,使用以下代码设置可见性:
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
val = get(handles.checkbox2, 'Value');
if (val)
vis = 'on';
else
vis = 'off';
end
set(handles.h1, 'Visible', vis); %Set Visibility of first figure.
set(handles.h2, 'Visible', vis); %Set Visibility of second figure.
set(handles.h3, 'Visible', vis); %Set Visibility of third figure.
我认为您的主要问题是设置所有三个数字的可见性。
对于设置特定地物的可见性,最好的选择是保持该地物的控制柄
我建议在打开新地物时保留地物句柄:
h1=图;%打开新图形,并将图形句柄存储在h1中
h2=图;%打开新图形,并将图形句柄存储在h2中
h3=图;%打开新图形,并将图形句柄存储在h3中
我认为在GUIOpeningFcg
函数中创建(打开)图形的正确位置
使用向导工具创建新GUI时,Matlab生成以下代码:
function guiname_OpeningFcg(hObject, evevntdata, handles, varargin)
...
handles.output = hObject;
guidata(hObject, handles);
...
在代码行guidata之后(hObject,handles)代码>,您可以创建数字。
将图形句柄存储在handles
结构中,以便以后使用:
function guiname_OpeningFcg(hObject, evevntdata, handles, varargin)
...
handles.output = hObject;
guidata(hObject, handles);
h1 = figure; %Open first figure, and store figure handle in h1
h2 = figure; %Open second figure, and store figure handle in h2
h3 = figure; %Open third figure, and store figure handle in h3
handles.h1 = h1; %Store handle to first figure.
handles.h2 = h2; %Store handle to second figure.
handles.h2 = h2; %Store handle to third figure.
在回调函数中,使用以下代码设置可见性:
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
val = get(handles.checkbox2, 'Value');
if (val)
vis = 'on';
else
vis = 'off';
end
set(handles.h1, 'Visible', vis); %Set Visibility of first figure.
set(handles.h2, 'Visible', vis); %Set Visibility of second figure.
set(handles.h3, 'Visible', vis); %Set Visibility of third figure.
非常感谢。我也试过这种方法。它工作得很好,但是@serial的方法非常简单。谢谢。我也试过这种方法。它工作得很好,但是@serial的方法最简单。