Errors in 'MATLAB Function' Block in a Simulink model for a Polynomial Trajectory (Matlab 2019a)

4 Ansichten (letzte 30 Tage)
I have a model here to calculate the trajectory for a vehicle obstacle evasion manoeuvre. When I run the Simulink model I get this errors:
'Output 'sum_vector' has variable size but the upper bound is not specified; explicit upper bound must be provided.
Component:MATLAB Function | Category:Coder error'
'Error occurred in 'Ausweich_Wael/MATLAB Function'.
Component:Simulink | Category:Model error'
The code runs fine when I run it as a matlab file it gives out the required plot, but not in Simulink. Worked on it for a long time but couldn't find a solution. Hope somebody can help with this, I really require to finish the model urgently.
This is the Simulink model:
and following is the code in Matlab function:
% This function calculates the summation 'Σ[g_i(t/t_e)^i]' in the
% evasion trajectory Polynomial.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Function inputs: n = Order of the System, t_e = Time taken to complete manoeuvre
function sum_vector = fcn(n, t_e)
t_0 = 0; %Time at Start of the evasive maneuver [s]
t_s = 0.1; %Sample time
t = t_0:t_s:t_e; % t = current time/actual time (from start of manoeuvre to end with an increment of t_s)
sum_vector=zeros(1,length(t));
switch n %select the g_i corresponding to Order 'n' of the System
case 1
g_i = [3 -2];
case 2
g_i = [10 -15 6];
case 3
g_i = [35 -84 70 -20];
case 4
g_i = [126 -420 540 -315 70];
case 5
g_i = [462 -1980 3465 -3080 1386 -252];
case 6
g_i = [1716 -9009 20020 -24024 16380 -6006 924];
case 7
g_i = [6435 -40040 108108 -163800 150150 -83160 25740 -3432];
end
for j = 1:length(t)
sum = 0;
for i = n+1:(2*n)+1
sum = sum + g_i(i-n)*((t(j)/t_e)^i);
end
sum_vector(j) = sum;
end

Antworten (1)

stozaki
stozaki am 13 Jan. 2020
I think that 'sum_vector' is variable size output. So, it should define as 'coder.varsize('sum_vector',[min max])'.
I have configured to avoid the error, but I am not sure if the algorithm is correct.
Please refer following documentation.
Regards,
stozaki

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by