Unreachable handles, unable to delete panel

2 views (last 30 days)
Ihave a code something like it:
function [Constraints]=screensec()
if nargin >=2
ParentPanel=varargin{1};
else
ParentPanel=figure('Position', [200 300 600 300],...
'Toolbar','none','menubar','none');
end
%create array of level to ease the selection if unavailable later
LevelAr=['None';strcat(repmat({'Level_'},1,9)',cellstr(int2str([1:9]')))];
ConMod=[];
%Data for the first table
DesTitles= fieldnames(Output.Des);
SiDes= size(DesTitles,1);
DataDes=[DesTitles, repmat({'None'},SiDes,1)]
%Define number of nodes that can be selected
NbofNodes=1;
MainTable= uitable ('parent',ParentPanel,...
'units','normalized',...
'Position',[0 .7 .45 .3],'rowname',[],...
'columnname',{'Type' 'Stage'},...
'columnformat',{'char' {'None' 'Level_1'}},...
'columneditable', [false true true],'data', {'a';'b';'c'},...
'celleditcallback',@Add_Level);
function Add_Level(gcf,~,~)
%Check levels change, remove useless level (not in order)
Table=get(gcf,'data');
LevelNb= Table(:,2);
InClean=find(ismember(LevelAr(2:end),LevelNb)==0);
Level=InClean(1,1)-1;
[~,IndToCh]=ismember(LevelNb,LevelAr(2:end));
TableChange=(IndToCh>Level) %the +1 is to remove the 'None'
Table(TableChange,2)={'None'};
NewChoice=LevelAr(1:Level+2); %Create the new possibilities.
set(gcf,'data',Table,'columnformat',{'char' NewChoice'});
%Width of level panel
xsiz=0.33
try
delete(ConMod.ParentP(:))
ConMod=[];
end
%Reinitialize
if Level>0
for i=1:Level
ConMod.ParentP(i)=uipanel('units','normalized','parent', ParentPanel,...
'Position', [0+xsiz*(i-1) 0 xsiz .7],...
'title',['Level_',int2str(i)]);
ConMod.But.Min(i)=uicontrol('Parent', ConMod.ParentP(i),'units','normalized',...
'position',[.4 .9 .2 .1],'style','pushbutton',...
'string','All','callback',@All_Same);
ConMod.Level(i)= uitable('Parent', ConMod.ParentP(i),'units','normalized',...
'position', [0 0 1 .8],'rowname',[],...
'columneditable',[false true true true true],...
'columnname', {'Type' 'Min' 'Max' 'Min pos' 'Maxpos'});
end
end
end
end
My problem is that every time I call the function, I am able to set('ConMod.But.Min(i)','string',xxx), but I am unable to delete ConMod.ParentP(i) directly, "it does not exist". where does the handle goes when parent are defined?
Basically I just want to create panel (kind of boxes) that will handle different controls and be able to supress them every time to reinitilise and create new ones (overwrite).
Is there a best practice tutorial for dynamic gui like this?
Thank you in advance
  1 Comment
Jan
Jan on 15 Feb 2013
The posted function "function [Constraints]=screensec()" does not accept inputs. Therefore "if nargin >=2" cannot be true.
In "function Add_Level(gcf,~,~)" you redefine "gcf" as a local variable, such that the built-in function with the same name is not reachable anymore. This is not an error, but the effects may be surprising.
When you run "for i=1:Level", the loop is not entered for Level<1, so you can omit the check "if Level > 0".

Sign in to comment.

Accepted Answer

Jan
Jan on 15 Feb 2013
You've posted just some parts of the code, you call it "something like this". But the cause of the error is concealed in the real code, while the posted one cannot run at all. Therefore we cannot guess, what's exactly going on.
Matt Figs 41 GUI examples are without doubt a good manual for dynamic GUIs.
  3 Comments
Jan
Jan on 15 Feb 2013
I do not see global variables in your code. I usually store handles in a struct, and this struct in the figure using GUIDATA or SETAPPDATA.
Johan
Johan on 15 Feb 2013
ConMod=[];
I think it acts as a global variable in nested function as it appears in light blue (and works). It allows me to avoid playing with setappdata with which I am still feeling incomfortable.
Thank you,

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!