Borrar filtros
Borrar filtros

3d plot from scalar values- how to

13 visualizaciones (últimos 30 días)
Gary el 4 de En. de 2021
Comentada: Star Strider el 5 de En. de 2021
I have a transfer function of the form, G= (wn^2+2*s*zeta*wn)/(s^2+2*zeta*wn*s+wn^2)
I need a 3d plot to represent the relation between variation of zeta on rise time and overshoot of the system.
I could manage to get scalar values (3 arrays) for rise time, overshoot and zeta. Now how to do 3d plotting?
btw:I do not wish to use plot3
  4 comentarios
Cris LaPierre
Cris LaPierre el 4 de En. de 2021
Moving Gary's comment that was posted as an answer here.
for zeta = 0.5:0.01:2
sys = tf([2*zeta*wn wn^2],[1 2*zeta*wn wn*wn]);
m= stepinfo(sys);
All I need is a 3d plot to establish the relation between zeta, settling time and overshoot. I need to use surf. Can you help me out. How do I change the above code to accomplish that?
Cris LaPierre
Cris LaPierre el 4 de En. de 2021
Editada: Cris LaPierre el 4 de En. de 2021
First thing to do is capture your values in variables rather than displaying them. You can find examples of how to do this on the for documentation page.
Currently, you are not capturing enough data to create anyting other than a 3D line. A surface and a mesh are not options until you have results for all combinations of your X and Y values. See my reply below for more.

Iniciar sesión para comentar.

Respuestas (2)

Cris LaPierre
Cris LaPierre el 4 de En. de 2021
How do you have a scalar array? Scalars are by definition 1x1.
Surf/mesh requires the Z input be a matrix, so somehow you will need to reshape your data. X and Y can be vectors, where X is a vector corresponds to the columns of Z, and Y corresponds to the rows of Z. If they are matrices, they must be the same size as Z, and the X and Y values would be for the corresponding element in Z. If all your data is vectors, you can use the reshape function just for this.
When you are creating a plot, you result will look better if your independent variable(s) are strictly increasing or decreasing (if that is appropriate for your data).
You can see examples on the surf documentation page. You can also find a recent Answers post here.

Star Strider
Star Strider el 4 de En. de 2021
Try this:
t = linspace(0, 0.02, 100);
zeta = 0.5;
zetav = 0.5:0.01:2;
for k = 1:numel(zetav)
sys = tf([2*zetav(k)*wn wn^2],[1 2*zetav(k)*wn wn*wn]);
y(:,k) = step(sys,t);
m = stepinfo(sys);
st(k) = m.SettlingTime;
os(k) = m.Overshoot;
intrpv = t >= m.PeakTime;
stv(k) = interp1(t(intrpv), y(intrpv,k), st(k));
hs = surfc(zetav, t, y);
grid on
hold on
hst = plot3(zetav, st, stv, '-k');
hold off
legend([hs(1) hst], 'Step Surface', 'Settling Time')
view(70, 30)
I’m not certain how you want to plot ‘overshoot’, however you can probably adapt this to include it.
  2 comentarios
Gary el 5 de En. de 2021
Since Iam new to Matlab, can you explain the logic behind the code? Comments on the code would be helpful
Star Strider
Star Strider el 5 de En. de 2021
The code is cimply a variation on your original code, expanded to create and plot the step responses and settling time as a 3D plot.
The linspace call creates the time vector that will cause all the outputs of the step call to hjave the same number of rows. This is important in order to store the results in the ‘y’ matrix.
The ‘zetav’ vector is simply the ‘zeta’ values, created so that defining ‘zeta’ in each step of the loop doesn’t overwrite ‘zeta’ each time. It’s also used in the surfc call. The for loop then uses these to define ‘zeta’ in each step. Indices must be integers greater than 0 in MATLAB, so ‘k’ makes that possible.
The rest of the looop just calls and stores the various variables for each value of ‘zeta’. The interp1 call finds the value of the step output at the settling time using linear interpolation in each iteration in order to plot that in the plot3 call after the loop.
The rest of the code are simply the surfc and plot3 calls, to plot the surface created by the step outputs in the ‘y’ matrix, and the line of settling time values plotted as a black line on the surface.
The documentation for the other function calls will describe how they work and how to use them. With that documentation, the way I use them here should be readily apparent. You can expand the code to plot the overshoot values. I did not do that here because it is not obvious to me how to depict them on the plot.

Iniciar sesión para comentar.


Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.





Community Treasure Hunt

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

Start Hunting!

Translated by