在 GUI 中更改面板属性
我尝试了很多事情,并通过谷歌和 stackoverflow 查看了数千个关键字,而且我实际上总是遇到相同的(对我来说无用的)解决方案。
这是我的问题:
我有一个带有 uibuttongroup“Youpi”的 GUI,其中有两个单选按钮“visible”和“invi”。 我有另一个 uipanel“Tralala”。
我创建了以下代码:
function Youpi_SelectionChangeFcn(hObject,eventdata)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
case 'visible'
set(handles.Tralala, 'visible', 'on');
case 'invi'
set(handles.Tralala, 'visible', 'off');
otherwise
% Code for when there is no match.
end
它不起作用,并且我总是收到相同的错误消息(见下文)。 我做了这两个测试来找出问题出在哪里: _我通过 disp 函数更改了大小写:当我切换两个单选按钮时,消息会正确显示。它不是来自 SelectionChangeFcn 函数。 _在第一个名为“GUI_OpeningFcn”的函数中,我输入 set(handles.Tralala, 'visible', 'off');
并且它可以正常工作(例如,如果我运行 GUI)。
您知道为什么面板手柄从一种功能消失到另一种功能吗?
这是错误消息:
??? Undefined variable "Tralala" or class "handles.Tralala".
Error in ==> MaccorGUI>Youpi_SelectionChangeFcn at 272
set(handles.Tralala, 'visible', 'on');
Error in ==> hgfeval at 63
feval(fcn{1},varargin{:},fcn{2:end});
Error in ==> uitools.uibuttongroup.childAddedCbk>manageButtons at 80
hgfeval(cbk, source, evdata);
??? Error while evaluating uicontrol Callback
请帮我找到解决方案。
谢谢。
I tried many things and looked with thousant of keywords thru google and stackoverflow and I literally always fall on the very same (useless for me) solutions.
Here's my problem:
I have a GUI with a uibuttongroup "Youpi" with two radio buttons "visible" and "invi".
I have an other uipanel "Tralala" .
I create the following code:
function Youpi_SelectionChangeFcn(hObject,eventdata)
switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
case 'visible'
set(handles.Tralala, 'visible', 'on');
case 'invi'
set(handles.Tralala, 'visible', 'off');
otherwise
% Code for when there is no match.
end
It does not work and I get always the same error message (see below).
I made these two tests to figure out where the problem is from:
_I changed the case by a disp function : when I toggle my two radio buttons, the messages are displayed properly. It does not come from SelectionChangeFcn function.
_In the very first function, called "GUI_OpeningFcn" , I input set(handles.Tralala, 'visible', 'off');
and it works properly (e.g. I don't see the panel if I run the GUI).
Do you know why the panel handle disappears from one function to an other ?
Here's the error message :
??? Undefined variable "Tralala" or class "handles.Tralala".
Error in ==> MaccorGUI>Youpi_SelectionChangeFcn at 272
set(handles.Tralala, 'visible', 'on');
Error in ==> hgfeval at 63
feval(fcn{1},varargin{:},fcn{2:end});
Error in ==> uitools.uibuttongroup.childAddedCbk>manageButtons at 80
hgfeval(cbk, source, evdata);
??? Error while evaluating uicontrol Callback
Please help me find a solution.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我找到了解决方案。我不认为这是最好的,但至少它有效。
在“switch”之前,我添加了以下命令:
在 switch 中,我使用“a”而不是“handles”。
注意:它也适用于 guihandles(您可以通过这种方式访问handles.output)
Ok I found the solution. I don't think it is the best one but at least it works.
Before "switch" i added the following command:
And in the switch instead of using "handles" I use "a".
note: it works also with guihandles ( you can have access to handles.output this way)
您需要将句柄添加到选择更改函数定义中
You need to add handles to the selection change function definition
我创建了一个带有按钮的组面板,每次我是其中一个按钮时选择一个图像,他 m'aficher 每个按钮都有一个图像
谢谢你帮我找到源代码
我正在做
uipanel4_SelectionChangeFcn 函数(hObject、EVENTDATA、句柄)
% hObject句柄 To uipanel4中选中的对象
% 具有以下 EVENTDATA 结构字段(参见 UIBUTTONGROUP)
%EventName:字符串'SelectionChanged'(只读)
% OldValue:先前选择的对象的句柄,如果没有选择WAS,则为空
% NewValue:当前选定对象的句柄
% 带有句柄和用户数据的句柄结构(参见 GUIDAT)
if RadioButton1 == get(handles.radiobutton1, '值', 1)
设置(handles.axes4,'因为')
else radioButton2 == get(handles.radiobutton2, '值', 1)
设置(handles.axes4'人')
I created a group panel with a button each time I was one of the button selects an image he m'aficher each button has an image
thank you for helping me to find the source code
I'm doing it
uipanel4_SelectionChangeFcn function (hObject, EVENTDATA, handles)
% hObject handle To The selected object in uipanel4
% With The followings EVENTDATA structure fields (see UIBUTTONGROUP)
% EventName: string 'SelectionChanged' (read only)
% OldValue: handle Of The Previously selected object or empty if none selected WAS
% NewValue: handle Of The Currently selected object
% handles structure with handle and user data (see GUIDAT)
if RadioButton1 == get (handles.radiobutton1, 'value', 1)
Set (handles.axes4, 'because')
else radioButton2 == get (handles.radiobutton2, 'value', 1)
Set (handles.axes4 'man')