- 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!