I wrote a code which is a pattern of popupmenu and edit and static Iu control but it does not work, would you help me?
Afficher commentaires plus anciens
function test
e = uicontrol('Style','Edit','Units','Normalized','Position',[.4 .5 .2 .1]);
uicontrol('Style','text','Units','Normalized',...
'Position',[.2 .45 .2 .1],'String','Number of laminas');
uicontrol('Style','PushButton','Units','Normalized',...
'Position',[.4 .3 .2 .1],'String','Create','Callback',@b_clbck);
function b_clbck(hObject, eventdata, handles)
n = str2double(get(e,'String'));
create_figure(n)
end
function create_figure(n)
figure('Units','Normalize','Name','Mechanical Properties')
for k=1:n
uicontrol('Style','Edit','Units','Normalized',...
'Position',[.1 k/n-.75/n .1 .75/n],'String',sprintf('Lamina %#d',k));
uicontrol('Style','popupmenu','String',{'Graphite','Boron'},'Units','Normalized',...
'Position',[.25 k/n-.75/n .1 .75/n],'Callback',@c_clbck);
uicontrol('Style','Edit','Units','Normalized',...
'Position',[.38 k/n-.75/n .08 .75/n],'Callback',@d_clbck);
uicontrol('Style','text','Units','Normalized',...
'Position',[.35 (k/n)-.75/n .03 .75/n],'String','Qx=');
uicontrol('Style','pushbutton','Units','Normalized',...
'Position',[1 k/n-.75/n .08 .75/n],'Callback',@e_clbck);
end
function c_clbck(hObject, eventdata, handles)%popupmenu
idx=get(handles.c,'Value');
switch idx
case 1
S.Ex=7;
S.Ey=20;
case 2
S.Ex=5;
S.Ey=30;
otherwise
end
set(handles.c, 'UserData', S);
end
function d_clbck(hObject, eventdata, handles)%Qx
end
function e_clbck(hObject, eventdata, handles)%pushbutton
S = get(handles.c, 'UserData')
Ex=S.Ex;
Ey=S.Ey;
Qx=Ey/Ex;
set(handles.d,'string',Qx)
end
end
end
12 commentaires
Cris LaPierre
le 18 Fév 2021
Please provide more details on what you mean by "it doesn't work". What is it supposed to do and why is the current behavior not correct?
Elmira Jafari
le 18 Fév 2021
Cris LaPierre
le 18 Fév 2021
Share everything we would need to reproduce the error. You can use the paperclip icon to attach files to your post.
Elmira Jafari
le 18 Fév 2021
Elmira Jafari
le 18 Fév 2021
Cris LaPierre
le 18 Fév 2021
Part of the issue appears to be your callback function inputs. When you create your app programmatically, you only have 2 inputs, not 3. See this page. Because your callbacks have all been defined with 3, the following error:
Not enough input arguments.
Error in LiveEditorEvaluationHelperE1134043204>test/create_figure/c_clbck (line 32)
idx=get(handles.c,'Value');
Error while evaluating UIControl Callback.
Your inputs should be (src,events)
Elmira Jafari
le 18 Fév 2021
Elmira Jafari
le 18 Fév 2021
Cris LaPierre
le 18 Fév 2021
Elmira Jafari
le 18 Fév 2021
Rik
le 18 Fév 2021
In addition to what Cris told you: for general advice and examples for how to create a GUI have look at this thread.
Rik
le 19 Fév 2021
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

