GUI Compatibility Issues from Early 2000's Matlab script run on R2015a
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I am using a Matlab script written back in the early 2000's (I can't remember the version) on my current Matlab R2015a version, and I'm trying to run the GUI; however I am running into issues that have been documented here: GUI Compatibility. The issue is, the buttons created using uicontrol appear to be hidden by the Parent figure. From my understanding, for past Matlab versions (before R2014a), uicontrol buttons were always placed on top, but for later versions of Matlab, the buttons are now hidden if the Parent isn't specified. I have already tried add the Parent to 'figure', but for some reason only figure axes are displayed.
Am I doing something wrong when setting the uicontrol Parent to the figure? I am confused about where to proceed from here. A portion of the interface script is presented below. I'm fairly new to Matlab GUIs, but any insight would be appreciated. Thanks.
figure(...
'Units','pixel','pos',[300 100 300 400 ],...
'Name','Introduction',...
'visible','off',...
'NumberTitle','off',...
'MenuBar','none',...
'Color',[c1 c2 c3],...
'NextPlot','new');
axis off
button=uicontrol('Parent', figure,'BackGroundColor','g','Style','edit','Position',[.70 .90 .22 .05],...
'Units','normalized','String',num2str(length(a)),...
'CallBack','nueq=str2num(get(inp1B,''String'')); set(inp1B,''String'',num2str(length(a)));');
2 Kommentare
Walter Roberson
am 13 Sep. 2017
The problem is not with uicontrol hidden by parent figure: the problem is with uicontrol hidden by uipanel. Look for a later uipanel, especially one that has no children: the children of the uipanel should be set to be the graphic objects that are being hidden.
Antworten (1)
Rik
am 13 Sep. 2017
Do you need to keep this code compatible with the early 2000's one? Because my doc for uicontrol suggests the syntax c=uicontrol(parent,Name,Value). This code could work, but you call figure to get the parent handle, which might result in unexpected behavior. You can use the gcf function, or even better, use an explicit handle.
f_handle=figure(...
'Units','pixel','pos',[300 100 300 400 ],...
'Name','Introduction',...
'visible','off',...
'NumberTitle','off',...
'MenuBar','none',...
'Color',[c1 c2 c3],...
'NextPlot','new');
axis off
button=uicontrol('Parent', f_handle,'BackGroundColor','g','Style','edit','Position',[.70 .90 .22 .05],...
'Units','normalized','String',num2str(length(a)),...
'CallBack','nueq=str2num(get(inp1B,''String''));set(inp1B,''String'',num2str(length(a)));');
Also, I have never seen char inputs for the callback, but always function handles, so you might need to move that one to its own function.
(next time, use the {}Code button to format your code)
2 Kommentare
Walter Roberson
am 14 Sep. 2017
character strings for callbacks are evaluated in the base workspace. No arguments like hObject or event are provided: if you need to know the context then you need to use gcbo or the like.
This is valid, and it is the style that GUIDE used to generate. I do not recommend it though.
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!