Simulink Matlab function block output is inferred as a variable-size matrix, but its size is specified as inherited or fixed

조회 수: 97 (최근 30일)
Hello,
I have implemented the following simulink to generate a prediction using a trained neural network.
When I try to run the model, I receive the follwong error message:
'input4NN' is inferred as a variable-size matrix, but its size is specified as inherited or fixed. Verify 'input4NN' is defined in terms of non-tunable parameters, or select the 'Variable Size' check box and specify the upper bounds in the Size box.
The preprocessing of the data in the corresponding matlab function block looks as follows:
function [enablePrediction, input4NN] = fcn(IVT_Current, IVT_Voltage, maxTemp, minVoltage, SOClast)
data = [IVT_Current IVT_Voltage maxTemp minVoltage SOClast];
persistent inputStream;
IPlength = 300;
if isempty(inputStream)
inputStream = data;
else
inputStream = [inputStream; data];
end
if size(inputStream, 1) >= IPlength
enablePrediction = true;
newestDataStream = inputStream((end-IPlength):end, :);
input4NN = [newestDataStream(:, 1); newestDataStream(:, 2); newestDataStream(:, 3); newestDataStream(:, 4); newestDataStream(:, 5)];
else
enablePrediction = false;
input4NN = zeros(1500, 1);
end
end
I have read some forum entries regarding the variable-size error, but I was able to resolve it that way.
I need an IP vector of (1500, 1) of non-variabel-size for the prediction block. So OP of the preprocessing function should also be (1500, 1). I already created a variabel "input4NN" that es stored inside the model workspace and specified the dimensions of (1500, 1) as fixed.
I'm thankful for any further ideas/help.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2023년 5월 3일
There are issues with the code. The size of "inputStream" is going to grow indifinitely.
I suggest using a Buffer block to replace this MATLAB Function block.
If you don't have the Buffer block in your Simulink and its toolbox, I suggest assigning input4NN = zeros(1500, 1) at the beginning of the code. Use a counter to determine enablePredition. Assign input4NN like below
TempData = [newestDataStream(:, 1); newestDataStream(:, 2); newestDataStream(:, 3); newestDataStream(:, 4); newestDataStream(:, 5)];
input4NN(1:1500)=TempData(:);
  댓글 수: 2
Fangjun Jiang
Fangjun Jiang 2023년 5월 3일
Or, making this one line change should resolve the "input4NN is inferred ..." error.
input4NN(1:1500) = [newestDataStream(:, 1); newestDataStream(:, 2); newestDataStream(:, 3); newestDataStream(:, 4); newestDataStream(:, 5)];

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Array and Matrix Mathematics에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by