Error in simulink, the upper bound is not specified;

129 vues (au cours des 30 derniers jours)
Jirada Gosumbonggot
Jirada Gosumbonggot le 20 Nov 2017
Commenté : Walter Roberson le 26 Juil 2023
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

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Nov 2017
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 commentaires
Walter Roberson
Walter Roberson le 26 Juil 2023
Walter Roberson
Walter Roberson le 26 Juil 2023
Tuhina, please be more specific about what link you are hoping for.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by