4

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 :(

remus
  • 2,635
  • 2
  • 21
  • 46

1 Answers1

8

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.

grungetta
  • 1,089
  • 1
  • 7
  • 8
  • Yes. That's what I want - an animation (real-time simulation). Your solution works. Thanks! – remus Jul 31 '13 at 07:27
  • However, the simulation is slowed down a lot :( – remus Jul 31 '13 at 07:37
  • 2
    If you are using a continuous or a fast discrete sample time, you may want to run your MATLAB function block at slower discrete sample time, so that the animation is updated, say every second, and doesn't slow down too much the simulation. You'll have to use appropriate Rate Transition blocks to go to/from the continuous/fast discrete sample time from/to the slower discrete one. – am304 Jul 31 '13 at 08:18
  • Yeah, unfortunately quick and dirty solutions like the one I suggested often have slow and dirty performance. I think am304 offers a good possible improvement, though. – grungetta Jul 31 '13 at 19:18