Clear Filters
Clear Filters

How to link a pushbutton with edit box and axes in MATLAB GUI. to plot graph with single pushbutton based on values written in edit box by user?

4 views (last 30 days)
i wanted to plot graph of AM(modulated and demodulated both graphs) signal using a pushbutton with the help of values entered in edit box by user in MATLAB GUI.

Answers (1)

Praveen Reddy
Praveen Reddy on 15 Mar 2023
Hi Mohit,
I understand that you want to plot a graph with the data entered by a user in an edit field of MATLAB GUI. Here are some steps you can follow:
  • Create a figure window.
  • Create a UI axes.
  • Create an edit field component.
  • Create a push button. Associate a call back function with input parameters – UI axes, edit field for the push event.
  • In the call back function, parse the edit field and plot on the UI axes.
Attaching a small code snippet for your reference.
function buttonPlot
% Create a figure window
fig = uifigure;
% Create a UI axes
ax = uiaxes('Parent',fig,...
'Units','pixels',...
'Position', [104, 123, 300, 201]);
edit1 = uieditfield(fig,'Position',[420, 180, 100, 32]);
% Create a push button
btn = uibutton(fig,'push',...
'Position',[420, 218, 100, 22],...
'ButtonPushedFcn', @(btn,event) plotButtonPushed(btn,ax,edit1));
end
% Create the function for the ButtonPushedFcn callback
function plotButtonPushed(btn,ax,edit1)
%Extract the values entered in edit field. Eg : 1 5 7 8 12
x_values=str2num(edit1.Value);
plot(ax,x_values);
end
To know more about “str2num”, please refer to the following MATLAB documentation:

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!