【发布时间】:2014-09-08 11:34:36
【问题描述】:
嗨
我想创建一个可以执行以下操作的 simulink 块。
1) 输入值与标准值相减,直到误差小于0.01。
例子
input value = 7,0005.
standard values = [1,2,3,4,5,6,7,8,9,10] or [1:n] the result would be 7.
我可以在matlab中做到,但我不知道如何在simulink中做到。
在 Matlab 中
a = 7,0005 % or any other input value
b = [1:10] % standard value
error = 1;
index = 0;
while error < 0.01
error = abs(a-b(index+1));
end
outputResult = b(index+1);
请帮帮我.......
【问题讨论】:
-
顺便说一句,您的代码中有一些错误:应该是
a = 7.005;,而不是a = 7,005。此外,您需要增加 while 循环中的索引值,并检查index+1不会超过length(b)。