GUI creation script has "matlab.gr​aphics.Gra​phicsPlace​holder/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))

 采纳的回答

Your code's a bit garbled, but what that error message is trying to say is that when it encounters this line:
set(h.eqdata(18),'Userdata',h.eqdata(19))
the variable eqdata(18) has not been set.
Earlier, when you executed this line:
h.eqdata(19) = uicontrol('Parent',h.panel(4),'Units','pixel',...
You created an array of 19 graphics handles. The first 18 are not initialized, and the 19th is set to a uicontrol. You cannot set or get properties on those 18 uninitialized handles.
Perhaps what you intended to do is to have each of those calls to uicontrol set one of the handles?

8 个评论

In R2014a and earlier, those uninitialized values would have been 0, and it is allowed to set() the UserData of object 0, so this would not have been noticed before R2014b. If that is the behaviour you want for some reason, then initialize the first 18 to groot() which is the new object that replaces object 0
thanks. i did not write this code, but it is used by 100's of people (seismology tool). that's why i'm thinking this might be an R2015 issue. i have someone sitting right here running it on R2014 with no problem. How would i use groot to fix this?
I think Walter's right. It "seemed to work" in earlier versions.
In earlier versions of MATLAB, because graphics objects were represented by doubles, uninitialized variables were a recurring problem. The value of an uninitialized double is 0, and
set(0,'Property','Value')
works for some properties.
OK. I'm not the best at matlab coding, but i just defined that variable to be 0 before the "set" line and it appears to be working now. thanks for the help!
No, it really isn't.
The object "groot" is a global object which is shared by all code in that MATLAB session. It would not be a good idea to save things in its UserData.
I think that the original author's intent was clearly to have initialized eqdata(18) to one of the objects that they created. Most likely, the return values of each of those calls to uicontrol were supposed to be saved in eqdata.
MAtLab 2015 really does not like the graphics in this code... Now i get another graphics error: ??
f(1) = plotm(latlow, lonlow, '--','Color',circleColor, 'linewidth',1);%SKSwindow
The following error occurred converting from matlab.graphics.primitive.Line to char:
Error using char
Conversion to char from matlab.graphics.primitive.Line is not possible.
Error in SL_showeqstats (line 121)
f(1) = plotm(latlow, lonlow, '--','Color',circleColor, 'linewidth',1);%SKSwindow
Error while evaluating UIControl Callback
It's probably the same thing. Because the graphics objects used to be represented by magic double values, there wasn't a lot of error checking in cases like this.
You can get this same error message with the following:
f = 'My String'
f(1) = plot(1:10)
You can reproduce what those old versions were doing by forcing the return value of plot to a double like this:
f = 'My String'
f(1) = double(plot(1:10))
But it's obviously a bad idea. In 14a, if you followed that code with this:
get(f(1))
You would get the following error message:
Error using get
Invalid handle
That's because the value that plot returned was a number like 174.0016. Because character strings are represented as 16 bit integers, this code is throwing away the fractional part of the value. This means that you can't use it to refer to the graphics object anymore.
This doc page talks about the transition from doubles to handles.

请先登录,再进行评论。

更多回答(1 个)

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 个评论

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
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')
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:
  1. 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
  2. That you have used global SkMp in the function and in the base workspace.
Neither of those are good programming practices.
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!

Translated by