Unreachable handles, unable to delete panel
이전 댓글 표시
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
Jan
2013년 2월 15일
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".
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Scripts에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!