Dimension varies error message on real time aplication

1 次查看(过去 30 天)
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 个评论
dpb
dpb 2021-7-12
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;

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Configure and View Diagnostics 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by