Error in simulink, the upper bound is not specified;

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

 Accepted Answer

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 Comments

Dear Walter
Thank you very much for your answer. I have tried put the coder.varsize in the code. But there's still same error happen at the output.
coder.varsize('V','I',zeros(10000,1));
Output 'V' has variable size but the upper bound is not specified; explicit upper bound must be provided.
I tried to set the upper bound as the maximum size of matrix. Not sure I've done it in the correct way or not.
Any suggestion for me? Thank you so much
coder.varsize('V', 'I', [10000,1], [1 0]); %first dimension is variable second is fixed
Dear Walter
Thank you, I key your command into my function but the same error still happen. Not sure why. Do I have to do additional setup for this?
I have solved the problem by setting up the data in the function to be variable and change the simulation mode from continuous to discrete and it works.
Thank you so much for your guidance, it helps me a lot
How to change the simulation mode to discrete? I have the same error even after using coder.varsize()
Did you try the syntax where you specify which dimension is to be variable or fixed? Without that, any dimension given as 1 is expected to mean "variable sized".
Hi all,
I'm having simular issue, when i try to use Matlab simulink to create a Android application which uses Image processing methods.When I add below code segment which uses to find the circle in the digital image,I'm getting "Declaration of upper bound size as Inf is not supported. " error.
[centers, radii, metric] = imfindcircles(image,[7 50]);
Since this is comming from a internal matlab function, I cannot change any code lines. Could please suggest me a solution. :)
Error stack:
Declaration of upper bound size as Inf is not supported. Function 'regionprops.m' (#52.56569.56624), line 1711, column 5: "coder.varsize('statsOneObj.PixelIdxList',[Inf 1],[1 0])" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'regionprops.m' (#52.2082.2162), line 75, column 1: "[stats, statsAlreadyComputed] = initializeStatsStruct(I, numObjs, TEMPSTATS_ALL)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'chcenters.m' (#53.1046.1092), line 36, column 5: "regionprops(bw,accumMatrix,'weightedcentroid')" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'imfindcircles.m' (#54.1318.1373), line 38, column 1: "[centers, metric] = chcenters(accumMatrix, accumThresh)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'MATLAB Function1' (#24.618.679), line 23, column 5: "[centers, radii, metric] = imfindcircles(resizedImage,[7 50])" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'centers'. The first assignment to a local variable determines its class. Function 'MATLAB Function1' (#24.619.626), line 23, column 6: "centers" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'radii'. The first assignment to a local variable determines its class. Function 'MATLAB Function1' (#24.628.633), line 23, column 15: "radii" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'metric'. The first assignment to a local variable determines its class. Function 'MATLAB Function1' (#24.635.641), line 23, column 22: "metric" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'another/MATLAB Function1'
Component:MATLAB Function | Category:Coder error
### Build procedure for model: 'another' aborted due to an error.
Errors occurred during parsing of MATLAB function 'another/MATLAB Function1'
That is odd. regionprops.m does not have nearly as many as 1711 lines, and line 75 is still in comments, and it has a createStatsStruct but no initializeStatsStruct . Which MATLAB release are you using, and what shows up for
which -all regionprops
I'm facing a similar issue. I'm using matlab 2019a. Can anyone please help.
My code segment is as follows:
[centers, ~, ~] = imfindcircles(BW3,[15 40]);
lines = houghlines(BW,theta,rho,P,'FillGap',5,'MinLength',10);
Error:
Declaration of upper bound size as Inf is not supported. Function 'regionprops.m' (#270.58241.58296), line 1756, column 5: "coder.varsize('statsOneObj.PixelIdxList',[Inf 1],[1 0])" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'regionprops.m' (#270.2092.2172), line 75, column 1: "[stats, statsAlreadyComputed] = initializeStatsStruct(I, numObjs, TEMPSTATS_ALL)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'chcenters.m' (#271.1046.1092), line 36, column 5: "regionprops(bw,accumMatrix,'weightedcentroid')" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'imfindcircles.m' (#272.1318.1373), line 38, column 1: "[centers, metric] = chcenters(accumMatrix, accumThresh)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'Image Processing System/MATLAB Function' (#246.351.377), line 17, column 11: "imfindcircles(BW3,[15 40])" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Declaration of upper bound size as Inf is not supported. Function 'houghlines.m' (#273.2046.2088), line 83, column 1: "coder.varsize('point1Array',[Inf,2],[1,0])" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function 'Image Processing System/MATLAB Function' (#246.485.538), line 20, column 9: "houghlines(BW,theta,rho,P,'FillGap',5,'MinLength',10)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'centers'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.612.619), line 27, column 6: "centers" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'centers'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.632.639), line 28, column 11: "centers" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'centers'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.692.699), line 30, column 27: "centers" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'centers'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.757.764), line 33, column 8: "centers" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'centers'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.775.782), line 33, column 26: "centers" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'centers'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.793.800), line 33, column 44: "centers" Launch diagnostic report.
Undefined function or variable 'lines'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.918.923), line 40, column 15: "lines" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'lines'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.1553.1558), line 56, column 20: "lines" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'lines'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.1731.1736), line 58, column 25: "lines" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'lines'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.1766.1771), line 59, column 17: "lines" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'lines'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.1808.1813), line 60, column 21: "lines" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'lines'. The first assignment to a local variable determines its class. Function 'Image Processing System/MATLAB Function' (#246.1847.1852), line 61, column 18: "lines" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Error limit reached. Suppressing further error messages. Function 'Image Processing System/MATLAB Function' (#246.1883.1888), line 62, column 18: "lines" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'untitled/Image Processing System/MATLAB Function'
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'untitled/Image Processing System/MATLAB Function'
Component:Simulink | Category:Model error
It looks to me as if you are not using R2018b, R2019a, or R2019b. Possibly you are using R2018a.
Thank you for responding.
I'm pretty sure that I'm using R2019a.
The issue has been resolved. I just enabled dynamic memory alocation by selecting the check box Dynamic memory allocation in MATLAB functions in the Simulation Target > Advanced parameters category.
In R2019a as far as I can see, the line
coder.varsize('statsOneObj.PixelIdxList',[Inf 1],[1 0]);
is at line 1756 of toolbox/images/images/eml/regionprops.m not at line 1711 .
Tuhina, please be more specific about what link you are hoping for.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!