how to save each array's results in dependent blank in GUI program base code?
Show older comments
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 laminate
f1 = 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);
end
end
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
end
end

3 Comments
Rik
on 19 Feb 2021
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
It is also not clear to me what your question is exactly. It is also difficult to understand your code, which is not helped by the lack of comments in your code.
Rik
on 19 Feb 2021
From your edit I get the feeling you are not the original author of this code. Did you contact the original author? You should keep your usage in the back of your mind when writting the code that generates fields with callbacks. Your code has several loops where data is getting overwritten and you do not seem to use object tags at all.
Elmira Jafari
on 19 Feb 2021
Accepted Answer
More Answers (0)
Categories
Find more on Connectivity to ROS-Enabled Simulators in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!