I have some arrays that would change their number by user inputs.
now assume 24 arrays we have, for each one , I have 2 results by pushing calculate button.
the result of all arrays are like the first one. while I expect the results of others change by changing its value of its pop up menu.
I dont know how give tag or index in program base GUI matlab?
other question is how could I revese the y direction , as you can see from pic my lamina 24 is on top of paper while lamina1 is at the end.
function laminatef1 = figure('Name','GUI','Menubar','none','Unit','normal','Position',[0.2 0.3 0.5 0.5])e = uicontrol('Style','Edit','Units','Normalized','Position',[.4 .5 .2 .1]);l = uicontrol('Style','text','Units','Normalized','Position',[.2 .45 .2 .1],'String','Number of laminas');m = uicontrol('Style','PushButton','Units','Normalized','Position',[.4 .3 .2 .1],'String','Create','Callback',@b_clbck); function b_clbck(hObject,eventdata) n = str2double(get(e,'String')); create_figure(n) end function create_figure(n) f2 = figure('Name','Mechanical properties','Menubar','none','Unit','normal','Position',[0.1 0.1 0.85 0.85]); up = uipanel('Title','laminates','Unit','normal','Position',[0.05 0.05 0.9 0.9]); for k=1:n; lam = uicontrol('Style','Edit','Units','Normalized','Position',[0.01 k/n-.75/n .1 .75/n],'String',sprintf('Lamina %#d',k),'parent',up); pop = uicontrol('Style','popupmenu','String',{'Graphite','Boron'},'Units','Normalized','Position',[.1 k/n-.75/n .1 .75/n],'Callback',{@popupmenu_callback},'parent',up); con1 = uicontrol('Style','text','Units','Normalized','Position',[.2 (k/n)-.75/n .03 .75/n],'String','Qx=','parent',up) res1 = uicontrol('Style','Edit','Units','Normalized', 'Position',[.22 k/n-.75/n .05 .75/n],'Callback',{@ans_callback},'parent',up); con2 = uicontrol('Style','text','Units','Normalized','Position',[.27 (k/n)-.75/n .03 .75/n],'String','Qy=','parent',up) res2 = uicontrol('Style','Edit','Units','Normalized', 'Position',[.30 k/n-.75/n .05 .75/n],'Callback',{@ans_callback},'parent',up); Cal = uicontrol('Style','pushbutton','Units','Normalized','Position',[0.7 k/n-.75/n .08 .75/n],'string','Calculate','Callback',{@Calc_callback},'parent',up); end function popupmenu_callback(hObject,eventdata) for k=1:n; idx = get(hObject,'value'); setappdata(0,'evalue',idx); endend function Calc_callback(hObject,eventdata)%pushbutton
for k=1:n; idx = getappdata(0,'evalue'); switch idx; case 1 % User selects Peaks.
ex=5; ey=20; Qx=ey/ex; Qy=ey*ex; set(res1,'string',Qx) set(res2,'string',Qy) case 2 % User selects Membrane.
ex=5; ey=30; Qx=ey/ex; Qy=ey*ex; set(res1,'string',Qx) set(res2,'string',Qy) otherwise end end end endend
Best Answer