I have created a GUI where I have created push buttons for output and linked them to plot a graph. Each code uses a few input parameters like frequency etc. I want to be able to input values in GUI using edit boxes which will change the output. How?

2 views (last 30 days)
I have created edit boxes for input parameters and want to link them to my output code in the callback of pushbuttons so that on changing input value, the code output changes leading to a change in the graph plot.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
c=3e11
N=16
freq= 3.3e9
dx=81
lamda= c/freq
K= 2*pi/lamda
theta_zero = 90;
An=1;
m=1;
for theta=-90:1:90
thetarad= (theta*pi)/180;
AF=0;
for n=0:N-1
AF= AF+An*exp(j*n*K*dx*(sin(thetarad)));
end
AFtheta(m)=AF
m=m+1;
end
maxAFtheta=max(AFtheta);
AFtheta=AFtheta/maxAFtheta;
AFtheta=abs(AFtheta);
plot(-90:1:90,20*log10(AFtheta));
%pushbutton1(handles.current_data);
My input boxes would be for dx, freq etc. How do i link my edit boxes for input to the code here? Thanks.

Accepted Answer

Geoff Hayes
Geoff Hayes on 7 May 2015
Aayush - you can use the handles structure (the third input to your callback) to reference the edit text controls. Note that this structure contains the handles to all of the controls of your GUI. So if you have an edit text box tagged as dx, then to grab this value you would do something like the following (in your callback)
dx = str2num(char(get(handles.dx,'String')));
The get(handles.dx,'String') returns a cell array so we need to convert it to a string or character array using char before converting the string to a number.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!