Plotting in Matlab appdesigner
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Claudee Khiarra Directo
el 14 de Feb. de 2021
Comentada: Mario Malic
el 5 de Nov. de 2022
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/518967/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/518972/image.png)
0 comentarios
Respuesta aceptada
Mario Malic
el 14 de Feb. de 2021
Editada: Mario Malic
el 14 de Feb. de 2021
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 comentarios
Ignacio Roa
el 5 de Nov. de 2022
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
el 5 de Nov. de 2022
Do some tutorials first and then post a question when you get stuck.
Más respuestas (1)
randerss simil
el 14 de Feb. de 2021
Editada: randerss simil
el 14 de Feb. de 2021
%if true
function GenerateButtonPushed(app,eventData)
It's eventdata instead of event
2 comentarios
randerss simil
el 14 de Feb. de 2021
Editada: randerss simil
el 14 de Feb. de 2021
The functuon input argument must call eventdata when the button is pushed.
Ver también
Categorías
Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!