如何在Simulink中对数组Y和X进行绘图?

时间:2021-10-03 20:26:43

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

我想在模拟运行的过程中建立一些tank配置文件并在Simulink中可视化。在Matlab中,我通常打字:

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

其中dX和Y是带有20个元素的数组(例如)。在Simulink中是否有可以绘制这个的范围或东西?X-Y图只绘制标量:(

1 个解决方案

#1


3  

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.

如果我正确地理解了你的问题,你的simulink模型就有了dX和Y的信号,它们都有20x1的尺寸。所以信号本身就是矢量,其值会随着时间而改变。如果是这样的话,那么您就会希望将其可视化为模拟正在运行的动画。也就是说,在simulink模拟的每一步,你会生成一个X-Y图来说明向量dX和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.

据我所知,范围和X-Y图形块不支持这个usecase。如果你的信号是随时间变化的标量值,那么X-Y图形将会是一种方法。但是正如你说的,因为你在处理矢量随时间变化的情况,X-Y图不是很有用。

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:

所以这可能是一个非常快速和肮脏的解决方案,但是你可能需要考虑使用一个MATLAB函数块并从里面调用plot函数。例如,块的内容可能如下所示:

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.

这个MATLAB函数块有两个输入,你可以把信号输入dX和Y。

#1


3  

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.

如果我正确地理解了你的问题,你的simulink模型就有了dX和Y的信号,它们都有20x1的尺寸。所以信号本身就是矢量,其值会随着时间而改变。如果是这样的话,那么您就会希望将其可视化为模拟正在运行的动画。也就是说,在simulink模拟的每一步,你会生成一个X-Y图来说明向量dX和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.

据我所知,范围和X-Y图形块不支持这个usecase。如果你的信号是随时间变化的标量值,那么X-Y图形将会是一种方法。但是正如你说的,因为你在处理矢量随时间变化的情况,X-Y图不是很有用。

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:

所以这可能是一个非常快速和肮脏的解决方案,但是你可能需要考虑使用一个MATLAB函数块并从里面调用plot函数。例如,块的内容可能如下所示:

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.

这个MATLAB函数块有两个输入,你可以把信号输入dX和Y。