필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Sébastien Malengé
Sébastien Malengé 2011년 5월 2일
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é
Sébastien Malengé 2011년 5월 2일
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