Effacer les filtres
Effacer les filtres

GUI Compatibility Issues from Early 2000's Matlab script run on R2015a

1 vue (au cours des 30 derniers jours)
Greg B.
Greg B. le 13 Sep 2017
Commenté : Rik le 14 Sep 2017
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 commentaires
Walter Roberson
Walter Roberson le 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.
Greg B.
Greg B. le 14 Sep 2017
Hi Walter, Thanks for your comment. It's weird, because the script that I'm using doesn't have a uipanel, so the uicontrol can't hide behind a uipanel. There's some other reason why the uicontrol buttons aren't showing up, and I just have no clue why! Could it be due to some property of either figure or uicontrol that's causing the issue, or potentially the positioning? Thanks for your help.
figure(...
'Units','pixel','pos',[300 400 300 400 ],...
'Name','General Parameters!',...
'Visible','off',...
'NumberTitle','off',...
'MenuBar','none',...
'Color',[c1 c2 c3],...
'NextPlot','new');
axis off
button=uicontrol('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)));');
set(gcf,'visible','on')

Connectez-vous pour commenter.

Réponses (1)

Rik
Rik le 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 commentaires
Walter Roberson
Walter Roberson le 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.
Rik
Rik le 14 Sep 2017
I was guessing it was an old syntax, thanks for confirming

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by