Plot bode inside UI axes of Matlab's app designer

1.8k views Asked by At

I am creating a UI on app designer and I want to plot a bode in my UI.axes.

enter image description here

This figure contains two plots (magnitude, phase) and what I want to do is to plot each plot in different ui.axes.

I've managed to plot only the magnitude bode and the phase bode using the following code :

clc;
clear all;

num = [2];
den = [conv([1 1], conv([1 1], [1 1]))];
sys = tf(num, den);

[mag, phase, freq] = bode(sys, {0.1, 100});
bodemag(sys, freq)

h = bodeplot(sys, freq);
setoptions(h,'MagVisible','off');

This code gives me these two seperate plots :

enter image description here

enter image description here

I am trying to insert these plots in two different ui axes in my app.

Does any one have an idea or another approach on how to insert the plots ?

NB : I've tried the following :-

  • Writing the code direcly into the app designer but it creates a pop up instead
  • Using the plot(app.UiAxes, ...., ....) function but I can't seem to make it work
1

There are 1 answers

0
Banditoka On

Can you show your code from appdesigner with the app.UIAxes. Which Matlab realease do you use ? As i know subplots are not supported in a UIAxes in older versions. So you have to make two UIAxes or use newer version.

If you write your code directly to appdesigner you are creating an Axes. There is an difference between UIAxes and Axes object. If you want to use Axes you have to set more properties to make it display inside your UIFigure of your App. You tried this ? I don't know if the UIAxes supports bodemag function. This could make sense, if it doesn't work with UIAxes.

bode = bodemag(app.UIAxes,sys, freq);

If UIAxes doesn't support bodemag then you have to do it with normal axes and code the positioning of this axes. This is a good example how to do it.: https://de.mathworks.com/help/matlab/creating_guis/polar-plotting-app-gui-in-app-designer.html

And this is the part that is required additional.

            % Create polar axes and position it in pixels
            app.Pax = polaraxes(app.UIFigure);
            app.Pax.Units = 'pixels';
            app.Pax.Position = [260 55 230 230];