GUI creation script has "matlab.gr​aphics.Gra​phicsPlace​holder/set​" error

12 ビュー (過去 30 日間)
Melissa Driskell
Melissa Driskell 2015 年 9 月 14 日
コメント済み: Victor Popov 2020 年 5 月 2 日
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))

採用された回答

Mike Garrity
Mike Garrity 2015 年 9 月 14 日
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 件のコメント
Mike Garrity
Mike Garrity 2015 年 9 月 16 日
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.
Melissa Driskell
Melissa Driskell 2015 年 9 月 16 日
thanks! this is so frustrating!!

サインインしてコメントする。

その他の回答 (1 件)

Victor Popov
Victor Popov 2020 年 4 月 29 日
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
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:
  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.
Victor Popov
Victor Popov 2020 年 5 月 2 日
Thanks so much for the valuable advice. I will definitely use them.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeJust for fun についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by