Borrar filtros
Borrar filtros

GUI cost button result MATlab

3 visualizaciones (últimos 30 días)
Oskar Kinat
Oskar Kinat el 6 de Dic. de 2020
Editada: Cris LaPierre el 6 de Dic. de 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)])

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 6 de Dic. de 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 comentarios
Oskar Kinat
Oskar Kinat el 6 de Dic. de 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 el 6 de Dic. de 2020
Editada: Cris LaPierre el 6 de Dic. de 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?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by