我正在使用Simulink块的MATLAB函数,我在那里定义的变量的界限有问题。
这是代码中我遇到麻烦的地方
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]"
谁能给我一个如何解决这个错误的想法?
提前谢谢。
发布于 2013-07-25 04:17:32
对于每个可变大小的数据输入/输出,您需要定义上限是什么。有关更多详细信息,请参阅http://www.mathworks.co.uk/help/simulink/ug/declare-variable-size-inputs-and-outputs.html。
发布于 2013-07-25 23:13:56
我能想到的唯一解决办法是手动编写一个具有固定循环边界的循环来扩展[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
https://stackoverflow.com/questions/17840392
复制相似问题