Error in simulink, the upper bound is not specified;

조회 수: 145 (최근 30일)
Jirada Gosumbonggot
Jirada Gosumbonggot 2017년 11월 20일
댓글: Walter Roberson 2023년 7월 26일
Hi,
I'm trying to simulate the code for choosing range of voltage and current. When I simulate and input the data (V and I are 3000x1 double).
The code is
function [V, I] = casechoose(V2,I2,V_drop_loc,Region,Isc_step)
persistent V2_full I2_full V2_half I2_half Isc_step_2 Isc_ratio I_shade2 V_shade2
if isempty(V2_full)
V2_full = [];
I2_full = [];
V2_half = [];
I2_half = [];
Isc_step_2 = 0;
Isc_ratio = 0;
I_shade2 = [];
V_shade2 = [];
end
if isempty(I2_full)
I2_full = 0;
end
datatype = 'double'
%%Find Isc_step_2
V2_full = V2(V2<0.9*(V2(end)) & V2>0.6*(V2(end))); % filter V2 value to be in 60-90% range of Voc
I2_full = I2(V2<0.9*(V2(end)) & V2>0.6*(V2(end))); % filter I2
V2_half = V2(V2<0.9*(V2(end)/2) & V2>0.6*(V2(end)/2));
I2_half = I2(V2<0.9*(V2(end)/2) & V2>0.6*(V2(end)/2));
I_shade2 = I2(V_drop_loc:end,:);
V_shade2 = V2(V_drop_loc:end,:);
Isc_step_2 = I_shade2(1);
Isc_ratio = Isc_step/Isc_step_2; % Isc_ratio as Main criteria
%%check the region
% Region = 1 (P_Gmppt is on LHS of the curve)
% Region = 2 (P_Gmppt is on RHS of the curve)
% Region 1
if Region ==1;
if Isc_ratio < 1 % case1
V = V2_full;
I = I2_full;
else
V = V2_half; % case2
I = I2_half;
end
else
if Isc_ratio > 1 % Region 2
V = V2_half; % case3
I = I2_half;
else
V = V2_full; % case4
I = I2_full;
end
end
Sorry it's a long code
The error that I get is
Output 'V' has variable size but the upper bound is not specified; explicit upper bound must be provided.
There's an error on size of the outputs V and I. I've tried setting the data in "Edit data" panel but does not work.
Any suggestion so far? Thank you so much in advance

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 20일
You should do one of the following:
  • use coder.varsize to declare a maximum size for V
  • initialize V to the largest permitted size for it before you assign anything else to it. Arrays defined this way are permitted to get smaller in later code but not larger than the initial assignment
  • put in assert() statements against size() of V2: you are taking a subset of V2 so V will never be larger than V2
  • or turn on dynamic memory allocation for V (not the preferred choice.)
  댓글 수: 14
Walter Roberson
Walter Roberson 2023년 7월 26일
Tuhina, please be more specific about what link you are hoping for.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by