how can I get a number from a popup menu and use it in Push Button

2 ビュー (過去 30 日間)
Abdulelah Alswaiyd
Abdulelah Alswaiyd 2017 年 2 月 26 日
回答済み: Jan 2017 年 2 月 26 日
I'm a beginner to MatLab GUI and I'm doing a very simple code .. this is the code for popup menu and pushbtn
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
val = get(handles.popupmenu2, 'value');
if (val==1);
S = 260*10^6
elseif (val==2);
S = 700*10^6
else
S = 400*10^6
end
sdf
function solvebtn_Callback(hObject, eventdata, handles)
% hObject handle to solvebtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
F = str2double( get(handles.force,'string'));
L = str2double( get(handles.length,'string'));
s = S
M = F*L/2;
W = sqrt(4*M/s);
H = 1.5*W;
set(handles.wvalue,'string' , W);
set(handles.hvalue,'string' , H);
here is my problem.. I know the way how I call S is completely wrong but I put it to show you that I want s to take the value of S selected in the popup menu
thank you
%

採用された回答

Jan
Jan 2017 年 2 月 26 日
I'm not sure what you are asking for. I assume it is how to provide the value of S to the other callback. Then:
function popupmenu2_Callback(hObject, eventdata, handles)
handles = guidata(hObject); % Not sure if handles is up to date already
switch get(handles.popupmenu2, 'value')
case 1
S = 260e6; % Cheaper than the power operation
case 2
S = 700e6;
otehrwise
S = 400e6;
end
handles.S = S;
guidata(hObject, handles); % Write back updates of "handles" struct
function solvebtn_Callback(hObject, eventdata, handles)
handles = guidata(hObject); % get current value
F = str2double(get(handles.force,'string'));
L = str2double(get(handles.length,'string'));
s = handles.S;
...
Does this help already?

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by