0

我正在使用 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)]

(向量[1x6]在哪里time_CAP_100

这是我得到的错误:

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]"

谁能告诉我如何解决这个错误?

提前致谢。

4

2 回答 2

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
于 2013-07-25T15:13:56.480 回答
0

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

于 2013-07-24T20:17:32.363 回答