HOW TO MAKE CODING FOR THIS FORMULA. I'M LITTLE BIT CONFUSING ABOUT STRNUM

1 回表示 (過去 30 日間)
nursuhailah suhaimi
nursuhailah suhaimi 2016 年 11 月 9 日
コメント済み: Image Analyst 2016 年 11 月 15 日
(popupmenu in GUI)
~ maximum power,MP =
2KWatt
4KWatt
~ value of resistance,VOR =
user will put any desire value
(pushbutton in GUI)
when press the pushbutton. then the answer will appear
Voltage = MP X VOR

回答 (1 件)

Geoff Hayes
Geoff Hayes 2016 年 11 月 11 日
nursuhailah - in the push button callback, you would get the value of the pop-up menu and the resistance value text, and do the appropriate calculation. For example,
function pushbutton1_Callback(hObject, eventdata, handles)
% get the maximum power
maxPower = 0;
maxPowerIdx = get(handles.popupmenu1,'Value');
if maxPowerIdx == 1
maxPower = 2;
elseif maxPowerIdx == 2
maxPower = 4;
end
% get the resistance
valueOfResistance = str2double(char(get(handles.edit1,'String')));
% do the calculation
voltage = maxPower * valueOfResistance;
% set the resistance
set(handles.text1,'String',num2str(voltage));
In the above, I'm assuming that your pushbutton is named pushbutton1, the popup menu is named popupmenu1, the resistance edit text field is named edit1, and the static text field where you are writing your answer is named text1. The above is untested but should give you an idea of how to proceed.
  2 件のコメント
nursuhailah suhaimi
nursuhailah suhaimi 2016 年 11 月 15 日
thank you so much ! :)
Image Analyst
Image Analyst 2016 年 11 月 15 日
If you have R2014b or later, you can do this, which is a more modern, object oriented way of doing it:
handles.text1.String = sprintf('Voltage = %f', voltage);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCounter and Timer Input and Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by