フィルターのクリア

GUI cost button result MATlab

3 ビュー (過去 30 日間)
Oskar Kinat
Oskar Kinat 2020 年 12 月 6 日
編集済み: Cris LaPierre 2020 年 12 月 6 日
Hi so I created a GUI that is supposed to go give me the cost of a parked car when I click on the "cost" button below in the picture but I just can't figure out how do take the result of the cost out of my command line and into the static text above the "cost"button. The code works but just not into the "static Text" box.
% --- Executes on button press in cost.
function cost_Callback(hObject, eventdata, handles)
% hObject handle to cost (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.output=hObject;
inverse_binary=not(handles.bw);
[handles.L handles.Num_object]=bwlabel(inverse_binary);
set(handles.text3,'string',);
imshow(handles.L, 'parent', handles.axes2);
guidata(hObject, handles);
disp('Parking Lots:')
disp('1: Short Term')
disp('2: Long Term')
LOT = input([' Enter the type of parking Lot (1: Short Term; 2: Long Term ) ']);
Weeks = input([' Enter the number of Weeks of parking) ']);
Days = input([' Enter the number of Days of parking) ']);
Hours = input([' Enter the number of hours of parking) ']);
Minutes = input([' Enter the number of Minutes of parking) ']);
if LOT==1 % Long Term parking
Hours = Hours + Minutes/60;
COST = Weeks*60 + Days*9 + 2 + ceil(Hours-1);
else % Short Term parking
Minutes = Minutes + Hours*60;
Days = Days + Weeks*7;
COST = Days*32 + 2 + ceil((Minutes-30)/20);
end
disp(['The Parking Cost in dollars is: ' num2str(COST)])

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 12 月 6 日
You'll need to set the Strng property of the static text box. Something like this should work (untested). I'm not sure what tag you've given your static text box, so I'm using handles.statictext.
msg = sprintf(['The Parking Cost in dollars is: ' num2str(COST)]);
set(handles.statictext, 'String', msg);
  2 件のコメント
Oskar Kinat
Oskar Kinat 2020 年 12 月 6 日
I am sorry to bother you again but it gives me a whole bunch of error messages. The tag is "text3".
Cris LaPierre
Cris LaPierre 2020 年 12 月 6 日
編集済み: Cris LaPierre 2020 年 12 月 6 日
Read the first line of the error messages. That is causing all the other problems. You are inside a function, so unless you define it inside the function or pass it in as an input to the function, COST doesn't exist.
Where is COST coming from? How is it set?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by