GUI cost button result MATlab
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Oskar Kinat
il 6 Dic 2020
Modificato: Cris LaPierre
il 6 Dic 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)])
0 Commenti
Risposta accettata
Cris LaPierre
il 6 Dic 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 Commenti
Cris LaPierre
il 6 Dic 2020
Modificato: Cris LaPierre
il 6 Dic 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?
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!