Clear Filters
Clear Filters

GUI cost button result MATlab

3 views (last 30 days)
Oskar Kinat
Oskar Kinat on 6 Dec 2020
Edited: Cris LaPierre on 6 Dec 2020
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)])

Accepted Answer

Cris LaPierre
Cris LaPierre on 6 Dec 2020
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 Comments
Oskar Kinat
Oskar Kinat on 6 Dec 2020
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 on 6 Dec 2020
Edited: Cris LaPierre on 6 Dec 2020
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?

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!