Updating edit text box in GUI
显示 更早的评论
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
采纳的回答
更多回答(1 个)
James Hendren
2013-7-10
1 个评论
It looks like there are two problems here. The first is causing your error. The second will cause problems later on:
1) You don't have a variable named AOI. Instead, you have a structure named handles, and that structure has a field named AOI. If you want to work with that field, you'll have to either call it directly or write it to a new variable. So something like this:
handles.AOI = str2double(get(hObject,'String'));
% phi=str2double(handles.AOI);
i=sind(handles.AOI)^.2;
b=sind(y2).^2;
And so on. Every time you want use that value, you need to reference it from the handles structure, because that's where it exists.
2) You need to name the value you pull out of your textbox something other than handles.AOI. This is because, along with the stuff you add to it, handles contains fields for every object in your GUI. Since your textbox's tag is "AOI," you're going to overwrite the reference to the textbox with that value you just pulled out and not be able to access the textbox again. This is why I suggested naming your angle of incidence value"handles.phi" instead of "handles.AOI."
handles.phi = str2double(get(hObject,'String'));
% phi=str2double(handles.phi);
i=sind(handles.phi)^.2;
b=sind(y2).^2;
c=tand(handles.phi).^2;
d=1+tand(handles.phi).^2;
e=tand(y1).^2;
f=1-tand(y1).^2;
g=(1-2*tand(y1)*cosd(y2)+tand(y1).^2).^2;
h=4*tand(y1)*sind(y2);
eps1 = (i*d*f.^2-4*e*b)./g;
eps2 = (i*c*h*f)./g;
plot(handles.axes3,x,y1);
plot(handles.axes4,x,y2);
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!