【问题标题】:Use the Output as the New Input into Matlab Function block in Simulink在 Simulink 中将输出用作 Matlab Function 模块的新输入
【发布时间】:2019-04-22 14:46:16
【问题描述】:

我的 Simulink 模型中的 Matlab Function 模块有三个输入。输入由一维数组thetaArray 和两个变量currentIndextrackingError 组成。 Matlab 函数块将输出两个变量,分别称为newIndextheta

使用newIndex 变量作为我在Matlab 函数块中的新输入的理想方法是什么?

Here is the image of my Simulink Model

这是模型中Matlab功能块的代码

function [newIndex,theta] = arraySelector(thetaArray,currentIndex,trackingError)

if currentIndex < length(thetaArray) && trackingError <= 0.00002
   newIndex = currentIndex + 1;
else
   newIndex = currentIndex;
end

theta = thetaArray(newIndex);
end

提前谢谢你。

【问题讨论】:

  • 通过单位延迟块发回。

标签: matlab simulink


【解决方案1】:

如果 theta 将是模型的输出和输入,您将拥有一个包含 algebraic loop

如果你的问题不清楚

  1. 需要在单个时间步内求解代数环或
  2. 您希望您的模型随着循环的每次迭代而及时推进。

对于第二种情况:

这是更简单的情况。 (在研究您的模型时更有可能)。在这里,您将打破循环,例如通过引入延迟块。延迟块的初始条件将是您现在在示例中定义的(块 theta_1)。

对于第一种情况:

按照How to Handle Algebraic Loops in a Model 中的说明进行操作。我建议您首先研究一个使用标量而不是数组的示例。您需要定义索引的初始条件,例如通过在循环中引入一个 IC-Block(就像您对 trackingerror 所做的那样)。如果 simulink 仍然无法解决代数循环,请考虑在您的 Matlab 功能块中使用替代实现,它会改变您的输入状态。 from direct feedthrough to non-direct feedthrough

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-09
    相关资源
    最近更新 更多