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 日

0 投票

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 件のコメント

Claudee Khiarra Directo
Claudee Khiarra Directo 2021 年 2 月 14 日
I tried this before, and still doesn't work.
Mario Malic
Mario Malic 2021 年 2 月 14 日
Do you see any errors showing up? Is app.UIAxes the actual plot handle of your uiaxes component?
I tried both of commands and both of them work. Something else is going on, check if n_range and xn are properly generated.
Claudee Khiarra Directo
Claudee Khiarra Directo 2021 年 2 月 14 日
no errors really. And yes, app.UIAxes is the plot handle of the UIAxes component. When I ran the similar code in a live script it ran.
amplitude = 200;
samples = 11;
n_range1 = -5;
n_range2 = 5;
n_range = n_range1:n_range2;
xn = amplitude .* sin(2*pi*randn(1,samples));
stem(n_range, xn);
Claudee Khiarra Directo
Claudee Khiarra Directo 2021 年 2 月 14 日
The above code generated a stem plot. I can't seem to implement it on the created app in app designer.
Mario Malic
Mario Malic 2021 年 2 月 14 日
Read my edit.
Claudee Khiarra Directo
Claudee Khiarra Directo 2021 年 2 月 14 日
I just read your edit, thank you it worked.
Mario Malic
Mario Malic 2021 年 2 月 14 日
Please accept my answer (blue button), thanks in advance.
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 日

0 投票

%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

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by