% --- Exe
cutes on button press in btnCalc.function btnCalc_Callback(hObject, eventdata, handles)% hObject handle to btnCalc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
gasTank = str2num(get(handles.tankEdit, 'string')); % Assigns 'gasTank' to the text field containing the size of the gas tank
gasPrice = str2num(get(handles.priceEdit, 'string')); % Assigns 'gasPrice' to the text field containing the cost of gas per gallon
gasBought = str2num(get(handles.boughtEdit, 'string')); % Assigns 'gasBought' to the text field containing the amount of gas purchased
dist = str2num(get(handles.app.distEdit, 'string')); % Assigns 'dist' to the text field containing the distance traveled in miles
galUsed = gasTank - gasBought ; % Calculates amount of gas consumed since last odometer reset
mpg = dist / galUsed ; % Calculates miles per gallon over the distance traveled
cpm = gasPrice / mpg ; % Calculates the cost per mile for the user to travel the distance covered
set(handles.mpgEdit,'string',num2str(mpg)); % Displays calculated miles per gallon
set(handles.cpmEdit,'string',num2str(cpm)); % Displays cost per mile of travel
These are the error messages that the command window throws when I input values and run the code I've written into this callback :
Reference to non-existent field 'app'.Error in mpgCalculator>btnCalc_Callback (line 177)dist = str2num(get(handles.app.distEdit, 'string')); % Assigns 'dist' to the text field containing the distance traveled in milesError in gui_mainfcn (line 95) feval(varargin{:});Error in mpgCalculator (line 42) gui_mainfcn(gui_State, varargin{:});Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)mpgCalculator('btnCalc_Callback',hObject,eventdata,guidata(hObject)) Error while evaluating UIControl Callback.
Best Answer