Attempt to reference field of non-structure array...

1 次查看(过去 30 天)
Hi, this is my code :
function [] = Test()
S.f = figure('units','pixels',...
'position',[500 500 200 130],...
'menubar','none',...
'numbertitle','off',...
'name','Run Scenarios',...
'resize','off');
S.po = uicontrol('style','popupmenu',...
'units','pix',...
'position',[10 60 180 60],...
'string','Power Initialization');
S.pb = uicontrol('style','pushbutton',...
'units','pix',...
'position',[10 20 180 30],...
'string','Make your choice',...
'callback',{@pb_call,S});
function [] = pb_call(varargin)
% Callback for Test pushbutton.
S = varargin{3}; % Get the structure.
G = get(S.po,'value');
model_path = 'D:\MATLAB\GUI\';
scenarios_path = [model_path 'Scenarios\'];
scenarios_p = dir([scenarios_path 'TS_Sy_MooN_P_*.m']);
path(path,model_path);
path(path,scenarios_path);
if G == 1
P.f = figure('units','pixels',...
'menubar','none',...
'position',[750 500 300 130],'name','Power Initialization Scenarios'); % Create a new GUI.
P.po = uicontrol('style','popupmenu',...
'units','pix',...
'position',[10 60 180 60],...
'string',{scenarios_p.name});
P.pb = uicontrol('style','pushbutton',...
'units','pix',...
'position',[10 20 180 30],...
'string','Run Scenarios',...
'callback',{@P_call,S});
end
function [] = P_call(varargin)
P = varargin(3);
X = get(P.po,{'string','val'});
if ~isempty(X{2})
run(scenarios_p(X{2}).name);
end
close(gcbf)
When I use the pushbutton of the second GUI, I have this error :
??? Attempt to reference field of non-structure array.
Error in ==> Test>P_call at 46 X = get(P.po,{'string','val'});
??? Error while evaluating uicontrol Callback
And I don't understand why... Thanks !

回答(1 个)

Sébastien Malengé
I find my mistake (P = varargin(3) must be varargin{3})

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by