2013-07-24 81 views
0

我正在使用Simulink模塊MATLAB FUNCTION,並且遇到了我在那裏定義的變量邊界問題。由於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]" 

任何人都可以給我一個如何解決這個錯誤的想法嗎?

在此先感謝。

回答

0

對於每個可變大小的數據輸入/輸出,您需要定義上限是什麼。有關更多詳情,請參閱http://www.mathworks.co.uk/help/simulink/ug/declare-variable-size-inputs-and-outputs.html

+0

謝謝你的友好的答覆,但我仍然有同樣的問題。我遇到問題的變量不是輸入/輸出信號。 – user2615539

+0

我已經限制了所有的輸入/輸出信號,但它沒有工作。我還嘗試將有問題的變量('tcharging_a1_2')作爲輸出信號進行陳述,並使用編輯數據框的選項來限制它。不過,我仍然得到相同的錯誤 – user2615539

+0

嗯......你需要用'coder.varsize'函數聲明你的變量(http://www.mathworks.co.uk/help/simulink/slref/coder。 varsize.html)? – am304

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 
+0

非常感謝! – user2615539

相關問題