Plotting in Matlab appdesigner

조회 수: 26 (최근 30일)
Claudee Khiarra Directo
Claudee Khiarra Directo 2021년 2월 14일
댓글: Mario Malic 2022년 11월 5일
I'm trying to create a random signal generator with stem plot in Matlab App Designer, and when I click the 'Generate' Button - nothing happens. Below is the code I added in the generated code from the app designer.
methods (Access = private)
%generate button is pushed
function GenerateButtonPushed(app, event)
amplitude = app.AmplitudeEditField.Value;
samples = app.SamplesEditField.Value;
n_range1 = app.nRange1EditField.Value;
n_range2 = app.nRange2EditField.Value;
n_range = n_range1:n_range2;
xn = amplitude .* sin(2*pi*randn(1,samples));
%plot random signal
stem(n_range,xn, 'parent', app.UIAxes)
end
end
When I ran this block of code in a live script in Matlab. It worked, but the graph won't show when I run it with the GUI.

채택된 답변

Mario Malic
Mario Malic 2021년 2월 14일
편집: Mario Malic 2021년 2월 14일
Hello,
Try this
stem(app.UIAxes, n_range,xn);
Edit: Both of these functions work, actually, the error is in writing a callback manually without assigning it to the component. In App Designer, click the right mouse button on the button component and go to callbacks and add one. Then you paste the body of your code in it.
  댓글 수: 9
Ignacio Roa
Ignacio Roa 2022년 11월 5일
hello,
I need some help, im tying to plot a pwm signal with a slider to control de dutycicle but i dont want to have to press a botom every time i change the duty. I have no idea how to do it.
Mario Malic
Mario Malic 2022년 11월 5일
Do some tutorials first and then post a question when you get stuck.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

randerss simil
randerss simil 2021년 2월 14일
편집: randerss simil 2021년 2월 14일
%if true
function GenerateButtonPushed(app,eventData)
It's eventdata instead of event
  댓글 수: 2
randerss simil
randerss simil 2021년 2월 14일
편집: randerss simil 2021년 2월 14일
The functuon input argument must call eventdata when the button is pushed.
Claudee Khiarra Directo
Claudee Khiarra Directo 2021년 2월 14일
changed it to eventData, and still no stem plot showing up in the GUI

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by