Evaluate if pushbutton is pressed in conditional 'if'
6 ビュー (過去 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!