- 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.
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?
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Praveen Reddy
2023-3-15
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:
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:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!