Borrar filtros
Borrar filtros

how to get value from pop-up menu in GUIDE without using automatic generate m.file

1 visualización (últimos 30 días)
i need code for pop-up menu in GUIDE without using automatic generate m.file
i select GUI option to generate fig file only and i create m-files for the GUI. i need to get value from list in pop-up menu for my calculate button.
this is my coding in the m-files
function twowayslab_wan
fig=openfig('twowayslab_wan.fig');
h=guihandles(fig);
set(h.btn_calc,'Callback',@Calculate);
set(h.btn_clear,'Callback',@clear);
set(h.btn_exit,'Callback','Exit');
imshow('gambar_beam2.jpg','Parent',h.axs_slab)
function Calculate(varargin)
% Assign input data to input variables
Ly=str2double(get(h.txt_Ly,'string'));
Lx=str2double(get(h.txt_Lx,'string'));
qk=str2double(get(h.txt_Qk,'string'));
gk=str2double(get(h.txt_Gk,'string'));
h_wan=str2double(get(h.txt_h,'string'));
phi=str2double(get(h.txt_phi,'string'));
fcu=str2double(get(h.txt_fcu,'string'));
% i need to get value from pop-up menu for function below
for exmaple:
case '1'
type_wan = 1
c= 20
fy=460
case '2'
type_wan = 2
c= 30
fy=250
answer=calc(Ly,Lx,qk,gk,h_wan,phi,fcu,type_wan,fy,c);
Ra=sprintf(answer);
set(h.text_answer,'string',Ra)
end

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Mayo de 2016
popvalue = get(h.NameOfPopup, 'Value');
switch popvalue
case 1:
...
end
end
However with the code you show, your "h" variable is not in scope inside Calculate. Your indentation hints you might have been wanting to use a nested routine (which would be a good idea), but you are missing the "end" that matches "function twowayslab_wan" so your Calculate function is not nested.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by