GUI buttons won't do anything?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
AMS
el 27 de Abr. de 2015
Comentada: AMS
el 27 de Abr. de 2015
I'm writing the code for a psychrometric calculator for a thermodynamics class in college. I've never done anything with GUI before, and even though I thought I've followed my teacher's instructions to the letter, neither of the buttons I've made (Calculate and Stop) seem to be doing anything. The only places where I changed the code from what the guide gave me was in the Calculate and Stop button sections if that helps narrow things down. Thanks in advance for the help!!
function varargout = AMSPsychrometric(varargin)
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @AMSPsychrometric_OpeningFcn, ...
'gui_OutputFcn', @AMSPsychrometric_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before AMSPsychrometric is made visible.
function AMSPsychrometric_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to AMSPsychrometric (see VARARGIN)
% Choose default command line output for AMSPsychrometric
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes AMSPsychrometric wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = AMSPsychrometric_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% CALCULATE button
function pushbutton1_Callback(hObject, eventdata, handles)
clc;
% Retrieve the three given values
T_drybulb=str2double(get(handles.edit1,'string'));
T_wetbulb=str2double(get(handles.edit2,'string'));
P_atm=str2double(get(handles.edit3,'string'));
% Equation 1 (saturation vapor pressures):
% Define the constant coefficients of the equation
a1=-5800.220; a2=1.3914993; a3=-0.0486402390; a4=41.764768*10^(-6); a5=-14.452093*10^(-9); a6=0.0; a7=6.5459673;
% Switch temperatures to Kelvin
Tk_db=273.15+T_drybulb;
Tk_wb=273.15+T_wetbulb;
% Solve for dry bulb
P_sat_db=0.001*exp((a1/Tk_db)+a2+a3*Tk_db+a4*Tk_db^(2)+a5*Tk_db^(3)+a6*Tk_db^(4)+a7*ln(Tk_db));
% Solve for wet bulb
P_sat_wb=0.001*exp((a1/Tk_wb)+a2+a3*Tk_wb+a4*Tk_wb^(2)+a5*Tk_wb^(3)+a6*Tk_wb^(4)+a7*ln(Tk_wb));
% Equation 2 (specific saturation humidity for wet bulb):
w_sat_wb=(0.622*P_sat_wb)/(P_atm-P_sat_wb);
% Equation 3 (enthalpy for water vapor at dry bulb temperature):
h_g_db=2501.3+1.82*T_drybulb;
% Equation 4 (enthalpy for liquid water at wet bulb temperature);
h_f_wb=0.0005*T_wetbulb^(2)+4.2105*T_wetbulb-0.0675;
% Equation 5 (latent heat of vaporization):
h_fg_db=2501-2.38*T_drybulb;
h_fg_wb=2501-2.38*T_wetbulb;
% Equation 6 (specific humidity):
w=(1.005*(T_wetbulb-T_drybulb)+w_sat_wb*h_fg_wb)/(h_g_db-h_f_wb);
% Equation 7 (relative humidity):
phi=(w*P_atm)/((0.622+w)*P_sat_db)*100;
% Equation 8 (vapor pressure):
P_v=phi*P_sat_db/100;
% Equation 9 (enthalpy):
h=1.005*T_drybulb+w*h_g_db;
% Equation 10 (specific volume):
v=0.287055*Tk_db/(P_atm-P_v);
% Equation 11 (dew point temperature):
T_dp=-35.957-1.8726*ln(1000*P_v)+1.16893*(ln(l000*P_v)^2);
% Set the boxes on the display to their respective values
% dew point temperature
set(handles.edit4,'string',num2str(T_dp))
% relative humidity
set(handles.edit5,'string',num2str(phi))
% specific humidity
set(handles.edit6,'string',num2str(w))
% saturation vapor pressure
set(handles.edit7,'string',num2str(P_sat_db,P_sat_wb))
% actual vapor pressure
set(handles.edit8,'string',num2str(P_v))
% specific volume
set(handles.edit9,'string',num2str(v))
% enthalpy
set(handles.edit10,'string',num2str(h))
% STOP button
function pushbutton2_Callback(hObject, eventdata, handles)
close all;
delete(gcf); % gcf=get current figure handle
return;
% Dry Bulb
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% Wet Bulb
function edit2_Callback(hObject, eventdata, handles)
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% Atmospheric Pressure
function edit3_Callback(hObject, eventdata, handles)
function edit3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% dew point temperature (C)
function edit4_Callback(hObject, eventdata, handles)
function edit4_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% relative humidity (%)
function edit5_Callback(hObject, eventdata, handles)
function edit5_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% specific humidity (kg/kg)
function edit6_Callback(hObject, eventdata, handles)
function edit6_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% saturation vapor pressure (kPa)
function edit7_Callback(hObject, eventdata, handles)
function edit7_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% actual vapor pressure (kPa)
function edit8_Callback(hObject, eventdata, handles)
function edit8_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% specific volume (m3/kg)
function edit9_Callback(hObject, eventdata, handles)
function edit9_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% enthalpy (kJ/kg)
function edit10_Callback(hObject, eventdata, handles)
function edit10_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
0 comentarios
Respuesta aceptada
Image Analyst
el 27 de Abr. de 2015
Does it go into the callback function at all? Did you set a breakpoint there and see if it stops there? Here is the solution to virtually all questions in this forum: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
Más respuestas (1)
Julia
el 27 de Abr. de 2015
Hi,
my impression is, that you should call a script with the calculate button instead of writing the whole function there.
After setting the values for your edit boxes, you have to update the handles structure.
% Update handles structure
guidata(hObject, handles);
3 comentarios
Julia
el 27 de Abr. de 2015
- Did you replace your code with a simple function call?
- Do you know that the variables are nonzero? Or do you assume ?
Adam
el 27 de Abr. de 2015
You actually don't need the guidata line if all you are doing with handles is updating the properties of one of the UI components, but it certainly doesn't do any harm and for any data added to or altered in the handles structure you do need this.
As Image Analyst points out below, debugging and putting a breakpoint in will answer your question very quickly though.
I would also very much second Julia's other advice on putting the actual calculation in its own function file. Keep the UI file as simple as possible with all the calculations done in files that you call from the callbacks, not in the callbacks themselves. Then you can test the function on the command line to check it is correct before you worry about whether the UI callback is working.
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!