Dimension varies error message on real time aplication

1 view (last 30 days)
Hi everyone,
I'm trying to run my code, which is defined on a Matlab Function on Simulink, on a real time target PC.
This is my code:
%--------------------------------------------------------------------------
% Inicialización de variables
%--------------------------------------------------------------------------
if k > H+1
yp = yk(k-H:k-1,1);
else
yp = zeros(H,1);
end
up = xf;
% Si Hc es menor que H
for i=(Hc+1):H
up(:,i)=up(:,Hc);
end
H has a constant value of 4
K is a value that can vary from 1 to 400 on each iteration.
I have predefined yp as a 4x1 vector, and as you can see in the code that I attach, yp is always going to be a 4x1 dimension vector. However, the error message that pops out after running the scripts (that you can also see in the following screenshot) says that the dimension of yk varies.
I don`t understand what is happening and why it says that its dimension varies if I have defined it clearly that it is a 4x1 vector.
Thanks a lot.
  1 Comment
dpb
dpb on 12 Jul 2021
yp = yk(k-H:k-1,1);
The subscript expression k-H:k-1 certainly is NOT a constant expression even though it computes to four elements in length. It appears the parser can only check and accept invariant expressions in whatever context it is that the code is being used in Simulink (which I don't have so can't test anything).
What happens if you assign the RHS to a temporary variable instead and then assign it to yp? The runtine should then see the result matches...
ytmp = yk(k-H:k-1,1);
yp=ytmp;

Sign in to comment.

Answers (0)

Categories

Find more on Configure and View Diagnostics in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!