GUI cost button result MATlab

1 view (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.L handles.Num_object]=bwlabel(inverse_binary);
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);
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);
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)


Find more on Interactive Control and Callbacks in Help Center and File Exchange





Community Treasure Hunt

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

Start Hunting!