GUI creation script has "matlab.graphics.GraphicsPlaceholder/set" error
显示 更早的评论
R2015a.
I am using a code that creates a GUI with different tabs. I get an error in the middle of the GUI creation so that part of the GUI pops up, but it is not complete and the script stops. Any ideas
what is wrong?:
Error using matlab.graphics.GraphicsPlaceholder/set
The name 'Userdata' is not an accessible property for an instance of class
'matlab.graphics.GraphicsPlaceholder'.
Error in configpanelUSER (line 64)
set(h.eqdata(18),'Userdata',h.eqdata(19))
Error in splitlab (line 39)
configpanelUSER;
The Script "configpanelUSER" runs as below until the last line below:
% Splitlab Configuration GUI helper function
x = 15;
y = 160;
w = 305;
v = 15;
h.panel(4) = uipanel('Un
if true
% code
endits','pixel','Title','User info','FontSize',10,'Position',[130 205 425 210], 'BackgroundColor', [224 223 227]/255 );
%%field descriptions text
txt = {'User name:';
'Institut:';
'Adress:';
'Phone:';
'Fax:';
'email:'};
for i=0:5
uicontrol('Parent',h.panel(4),'Units','pixel',...
'Style','text',...
'Position',[x y-(i*v*2) 200 20],...
'String', txt{i+1},...
'HorizontalAlignment','Left');
end
%%user and internet settings
x=100;
uicontrol('Parent',h.panel(4),'Units','pixel',...
'Style','Edit',...
'BackgroundColor','w',...
'Position',[x y w 20],...
'String', config.request.user,...
'Callback', 'config.request.user=get(gcbo,''String'');');
uicontrol('Parent',h.panel(4),'Units','pixel',...
'Style','Edit',...
'BackgroundColor','w',...
'Position',[x y-2*v w 20],...
'String', config.request.institut,...
'Callback', 'config.request.institut=get(gcbo,''String'');');
uicontrol('Parent',h.panel(4),'Units','pixel',...
'Style','Edit',...
'BackgroundColor','w',...
'Position',[x y-4*v w 20],...
'String', config.request.adress,...
'Callback', 'config.request.adress=get(gcbo,''String'');');
uicontrol('Parent',h.panel(4),'Units','pixel',...
'Style','Edit',...
'BackgroundColor','w',...
'Position',[x y-6*v w 20],...
'String', config.request.phone,...
'Callback', 'config.request.phone=get(gcbo,''String'');');
uicontrol('Parent',h.panel(4),'Units','pixel',...
'Style','Edit',...
'BackgroundColor','w',...
'Position',[x y-8*v w 20],...
'String', config.request.fax,...
'Callback', 'config.request.fax=get(gcbo,''String'');');
h.eqdata(19) = uicontrol('Parent',h.panel(4),'Units','pixel',...
'Style','Edit',...
'BackgroundColor','w',...
'Position',[x y-10*v-1 w 21],...
'String', char(config.request.usermail),...
'Callback','config.request.usermail=char(get(gcbo,''String''));');
set(h.eqdata(18),'Userdata',h.eqdata(19))
采纳的回答
更多回答(1 个)
Victor Popov
2020-4-29
0 个投票
When I use the command
set(aaa.uic3(:),'handlevisibility','callback')
the error message appears:
Error using matlab.graphics.Graphics/set
The name 'handlevisibility' is not an accessible property for an instance of class 'matlab.graphics.GraphicsPlaceholder'.
Any ideas what is wrong?:
4 个评论
Walter Roberson
2020-4-29
Some element in aaa.uic3 was not initialized to an actual graphics object, probably for reasons similar to discussed above as discussed by Mike in https://www.mathworks.com/matlabcentral/answers/242959-gui-creation-script-has-matlab-graphics-graphicsplaceholder-set-error#answer_192328
Victor Popov
2020-4-30
Thank you! I looked at the code more closely, but still did not understand what the problem was ... The code fragment and diagnostics are below
SkMp.uic3(1,1) = uimenu('Label','File');
SkMp.uic3(1,2) = uimenu(SkMp.uic3(1,1),...
'Label','Figure',...
'Callback','figure',...
'position',1);
SkMp.uic3(1,3) = uimenu(SkMp.uic3(1,1),...
'Label','Close',...
'Callback','skmp_close',...
'position',2);
SkMp.uic3(1,4) = uimenu(SkMp.uic3(1,1),...
'Label','Page setup',...
'Callback','pagesetupdlg',...
'position',3);
SkMp.uic3(1,5) = uimenu(SkMp.uic3(1,1),...
'Label','Print',...
'Callback','printdlg',...
'position',4);
SkMp.uic3(1,6) = uimenu(SkMp.uic3(1,1),...
'Label','Preferences',...
'position',5);
SkMp.uic3(1,7) = uimenu(SkMp.uic3(1,6),...
'Label','Default',...
'Callback','SkMp = s_preferences(SkMp,0);');
SkMp.uic3(1,7) = uimenu(SkMp.uic3(1,6),...
'Label','Plot',...
'Callback','SkMp = s_preferences(SkMp,2);');
SkMp.uic3(1,8) = uimenu(SkMp.uic3(1,6),...
'Label','Plot color',...
'Callback','SkMp = s_preferences(SkMp,3);');
SkMp.uic3(1,9) = uimenu(SkMp.uic3(1,6),...
'Label','Plot sizes',...
'Callback','SkMp = s_preferences(SkMp,4);');
SkMp.uic3(2,1) = uimenu('Label','Pos/time');
SkMp.uic3(2,2) = uimenu(SkMp.uic3(2,1),...
'Label','Display Pos/time',...
'Callback','skmp_disp_pos_time(SkMp)');
SkMp.uic3(2,3) = uimenu(SkMp.uic3(2,1),...
'Label','New Pos/time',...
'Callback',checkokstr);
SkMp.uic3(3,1) = uimenu('Label','Star');
SkMp.uic3(3,2) = uimenu(SkMp.uic3(3,1),...
'Label','Inform',...
'Callback','[SkMp,staraz,starze,starid,starmagn,thisstar] = updstrinfo(SkMp);');
SkMp.uic3(3,3) = uimenu(SkMp.uic3(3,1),'Label','Plot star spectra','Callback','plotspec');
SkMp.uic3(3,4) = uimenu(SkMp.uic3(3,1),'Label','assign star spectra','Callback','guigetspec');
SkMp.uic3(3,5) = uimenu(SkMp.uic3(3,1),'Label','Ra/decl','Callback',str0);
SkMp.uic3(3,6) = uimenu(SkMp.uic3(3,1),'Label','Azim/Zen','Callback',str1);
SkMp.uic3(4,1) = uimenu('Label','Help');
SkMp.uic3(4,2) = uimenu(SkMp.uic3(4,1),...
'Label','Help',...
'Callback','skyhelp(5)');
SkMp.uic3(4,3) = uimenu(SkMp.uic3(4,1),...
'Label','WARRANTY',...
'Callback','skyhelp(6)');
SkMp.uic3(4,4) = uimenu(SkMp.uic3(4,1),...
'Label','Copyright',...
'Callback','skyhelp(7)');
set(SkMp.uic3(:),'handlevisibility','callback') %%----- Line 167
Error using matlab.graphics.Graphics/set
The name 'handlevisibility' is not an accessible property for an instance of class 'matlab.graphics.GraphicsPlaceholder'.
Error in skymap (line 167)
set(SkMp.uic3(:),'handlevisibility','callback')
Walter Roberson
2020-4-30
SkMp.uic3(1,7) = uimenu(SkMp.uic3(1,6),...
'Label','Default',...
'Callback','SkMp = s_preferences(SkMp,0);');
SkMp.uic3(1,7) = uimenu(SkMp.uic3(1,6),...
'Label','Plot',...
'Callback','SkMp = s_preferences(SkMp,2);');
Notice that you are writing to the same location twice.
SkMp.uic3(1,9) = uimenu(SkMp.uic3(1,6),...
'Label','Plot sizes',...
'Callback','SkMp = s_preferences(SkMp,4);');
After that statement, SkMp.uic3() is M x N where N >= 9 and M is at least 1, possibly more if there were other initializations.
SkMp.uic3(2,1) = uimenu('Label','Pos/time');
Now that M x N is at least 2, and you have not initialized uic3(2,2:9) so they are set to be placeholder graphic objects.
SkMp.uic3(2,3) = uimenu(SkMp.uic3(2,1),...
'Label','New Pos/time',...
'Callback',checkokstr);
You stop at (2,3) so you have not initialized uic3(2,4:9)
SkMp.uic3(3,1) = uimenu('Label','Star');
Now uic3 is at least 3 x 9 with uic3(2,4:9) and uic3(3,2:9) not initialized yet.
SkMp.uic3(4,4) = uimenu(SkMp.uic3(4,1),...
'Label','Copyright',...
'Callback','skyhelp(7)');
skipping pointing out some things: after this, uic3 is at least 4 x 9, and uic3(2,4:9), uic3(3,7:9), uic3(4,5:9) are all not initialized.
What can you do? Well, you could
validobj = findobj(SkMp.uic3, '-flat', '-property', 'handlevisibility');
set(validobj, 'HandleVisibility', 'Callback');
Also,
SkMp.uic3(1,7) = uimenu(SkMp.uic3(1,6),...
'Label','Default',...
'Callback','SkMp = s_preferences(SkMp,0);');
Using quoted strings for callbacks is not recommended. The string indicated will be executed within the context of the base workspace, not within the context of any function, and especially not within the context of the function doing the assignments to SkMp.uic3 .
Since you are changing SkMp within the quoted string context, the only two ways that the result in the base workspace could refer to the same SkMp would be:
- That your code setting SkMp.uic3() is being executed outside of any function, in a pure script not called by any function, so that SkMp in the posted code is also referring to the base workspace; or
- That you have used global SkMp in the function and in the base workspace.
Neither of those are good programming practices.
Victor Popov
2020-5-2
Thanks so much for the valuable advice. I will definitely use them.
类别
在 帮助中心 和 File Exchange 中查找有关 Language Support 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!