由于Simulink Matlab功能块中的可变大小数据导致的错误

时间:2013-07-24 16:58:34

标签: variables size simulink

我正在使用Simulink块MATLAB FUNCTION,并且我在那里定义了变量的边界问题。

这是我遇到麻烦的代码的一部分

function P_S1_100= fcn(SOC_S1_100,S1_AGENTS_10,time_CAP_100)

         assert(time_CAP_100(1)<100)

         tcharging_a1_1=[0:0.05:time_CAP_100(1)]
         tcharging_a1_2=[time_CAP_100(1):0.05:time_CAP_100(1)*2]
         tcharging_a1=[0:0.05:time_CAP_100(1)]

(其中time_CAP_100是向量[1x6])

这就是我得到的错误:

Computed maximum size of the output of function 'colon' is not bounded.
Static memory allocation requires all sizes to be bounded.
The computed size is [1 x :?].

Function 'Subsystem1/Slow Charge/S1/MATLAB Function5' (#265.262.302), line 8, column   16:
"[time_CAP_100(1):0.05:time_CAP_100(1)*2]"

有人能告诉我如何解决这个错误吗?

提前致谢。

2 个答案:

答案 0 :(得分:0)

对于每个可变大小的数据输入/输出,您需要定义上限是什么。有关详细信息,请参阅http://www.mathworks.co.uk/help/simulink/ug/declare-variable-size-inputs-and-outputs.html

答案 1 :(得分:0)

我只能想到的是手动编写一个带有固定循环边界的循环来扩展[time_CAP_100(1):0.05:time_CAP_100(1)*2]。那个表达是导致问题的原因。你需要知道这个向量的界限。然后你可以写一个类似

的循环
% max_size is the maximum length possible for tcharging_a1_2
tcharging_a1_2 = zeros(1,max_size);
tcharging_a1_2(1) = time_CAP_100(1);
for ii=2:max_size
  if tcharging_a1_2(ii) < time_CAP_100(1)*2
    tcharging_a1_2(ii) = tcharging_a1_2(ii) + .05;
  end
end