How to plot array Y against X in Simulink?

remus picture remus · Jul 30, 2013 · Viewed 10.7k times · Source

I want to build some tank profiles and visualize them in Simulink while the simulation is running. In Matlab I usually type:

plot(dX, Y), grid;

where dX and Y are arrays with 20 elements (for example). Is there a scope or something in Simulink capable of plotting this? The X-Y graph plots only scalars :(

Answer

grungetta picture grungetta · Jul 30, 2013

If I'm understanding your question correctly, your simulink model has signals dX and Y which each have dimensions of, say, 20x1. So the signals themselves are vectors whose values will change over time. If that's the case, then you would expect to visualize this as sort of an animation as the simulation is running. That is to say, at each time step of the simulink simulation, you would generate an X-Y graph illustrating the relationship between vectors dX and Y.

To my knowledge the Scope and X-Y Graph blocks don't support this usecase. If your signals were scalar values that changed over time, the X-Y Graph would be the way to go. But as you said, since you are working with vectors changing over time, X-Y Graph isn't that useful.

So this may be a very quick and dirty solution, but you might want to consider just making use of a MATLAB Function Block and calling the plot function from within there. For example, the contents of the block might read as follows:

function fcn(x,y)
%#codegen

coder.extrinsic('plot')
plot(x,y)
% insert additional code as needed to turn on grid, setup axis limits, etc.

The MATLAB Function Block would have two inputs, into which you could feed your signals dX and Y.