Evaluate if pushbutton is pressed in conditional 'if'
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi everybody, Im trying to evaluate if a pushbutton is pressed and then plot my data in a UI. Here is the code:
function Results_after_opt()
%Results_after_opt is function that shows the main values obteined after
%the optimization and aproximation of the results
%
%Creation of the figure
fig = figure('units','pixels',...
'position',[10 850 265 155],...
'menubar','none',...
'name','Расчет АХ самолетов - Меню',...
'numbertitle','off',...
'resize','off');
res_after_opt = guihandles(fig);
%Figure in the center
scrsz = get(0, 'ScreenSize');
pos_act=get(gcf,'Position');
xr=scrsz(3) - pos_act(3);
xp=round(xr/2);
yr=scrsz(4) - pos_act(4);
yp=round(yr/2);
set(gcf,'Position',[xp yp pos_act(3) pos_act(4)]);
%---------------------------------------
%
hfig_res_opt= findobj('Tag','reswopt');
res_opt=guidata(hfig_res_opt);
%
%Components
res_after_opt.smin_m0 = uicontrol('Style','text', ...
'Units','pixels', ...
'Position',[5 95 150 25], ...
'String','min m0');
%
res_after_opt.min_m0=uicontrol('Style','text', ...
'Units','pixels', ...
'Position',[160 95 100 25], ...
'String',res_opt.min_m0);
%
res_after_opt.slz_opt_m0=uicontrol('Style','text', ...
'Units','pixels', ...
'Position',[5 65 150 25], ...
'String','lz opt m0');
%
res_after_opt.lz_opt_m0=uicontrol('Style','text', ...
'Units','pixels', ...
'Position',[160 65 100 25], ...
'String',res_opt.lz_opt_m0);
%
res_after_opt.snu_opt_m0=uicontrol('Style','text', ...
'Units','pixels', ...
'Position',[5 35 150 25], ...
'String','nu opt m0');
%
res_after_opt.nu_opt_m0=uicontrol('Style','text', ...
'Units','pixels', ...
'Position',[160 35 100 25], ...
'String',res_opt.nu_opt_m0);
%
res_after_opt.pb_surf=uicontrol('Style','pushbutton', ...
'Units','pixels', ...
'Position',[5 5 125 25], ...
'String','Surf b effective',...
'callback',@callback);
res_after_opt.pb_mesh=uicontrol('Style','pushbutton', ...
'Units','pixels', ...
'Position',[135 5 125 25], ...
'String','Mesh b effective',...
'callback',@callback);
guidata(fig,res_after_opt);
end
And the callback function.
function callback(hObject)
res_after_opt = guidata(hObject);
if res_after_opt.pb_surf==1
surf(res_opt.topl_ef(:,:));
elseif res_after_opt.pb_mesh==1
mesh(res_opt.topl_ef(:,:));
end
end
댓글 수: 0
채택된 답변
Jan
2018년 6월 15일
I guess you mean the Value of the objects:
function callback(hObject)
res_after_opt = guidata(hObject);
if res_after_opt.pb_surf.Value == 1
surf(res_opt.topl_ef);
elseif res_after_opt.pb_mesh.Value == 1
mesh(res_opt.topl_ef);
end
end
By the way, omit the "(:,:)" in x(:,:), because it wastes time only. x is sufficient and clear already.
댓글 수: 5
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!