MATLAB: Updating edit text box in GUI

edit textgui

So I need to pass a number from an edit text box in the GUI to an equation, and then graph it. The edit text box is the angle of incidence or phi. So whatever number I type I need it to equal phi. The using the phi/angle of incidence I can find my my values for eps1 &eps2. Help please
function AOI_Callback(hObject, eventdata, handles)
% hObject handle to AOI (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of AOI as text
% str2double(get(hObject,'String')) returns contents of AOI as a double
% --- Executes during object creation, after setting all properties.
function AOI_CreateFcn(hObject, eventdata, handles)
% hObject handle to AOI (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
global phi delta psi
psi=A(:,2)
delta=A(:,3)
phi= aoi
a=sin(phi).^2
b=sin(delta).^2
c=tan(phi).^2
d=1+tan(phi).^2
e=tan(psi).^2
f=1-tan(psi).^2
g=[1-2*tan(psi)*cos(delta)+tan(pis).^2].^2
h=4*tan(psi)*sin(delta)
eps1= (a*d*f.^2-4*e*b)./g
eps2 = (a*c*h*f)./g

Best Answer

Instead of putting your equation in the CreateFcn, put it in AOI_Callback.
Also, using the handles structure instead of global variables is much safer and easier, especially since you're using GUIDE to create your GUI. Something like this should work:
function AOI_Callback(hObject, eventdata, handles)
% hObject handle to AOI (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of AOI as text
% str2double(get(hObject,'String')) returns contents of AOI as a double
handles.phi = str2double(get(hObject,'String')); % Get the value entered in your editbox
%now perform your calculations here. If you want to save any of the variables you calculate, add them to the handles structure in the form handles.(variablename)
guidata(hObject,handles) %save the handles structure back out to your editbox. Now, you should be able to access the data you added to it in any other callback
% --- Executes during object creation, after setting all properties.
function AOI_CreateFcn(hObject, eventdata, handles)
% hObject handle to AOI (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
Related Question