- Try initializing A to zeros(4,4) or as appropriate.
- Right click on the block, select Explore (first option in menu) which will open the Model Explorer. You can manually set the sizes of the input and output ports as required. The default size is -1 which means Simulink should try to inherit the size by looking at the code in the block.
Block does not fully set the dimensions of output 'A'
106 次查看(过去 30 天)
显示 更早的评论
Hello!
I am trying to create an MPC controller according to the MATLAB guide (*https://www.youtube.com/watch?v=aQhpvrQPxD4&t=212s&ab_channel=MATLAB*).
I have already synthesyzed MPC controller for linearized system and now I want to create one for nonlinear system using the mpc controller I have already created.
Here is my problem:
Block ''Model_v1/Plant Model'' does not fully set the dimensions of output 'A'.
Component:Simulink | Category:Block error
Does anyone know how to fix this?
Here is my sctructure:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/550912/image.png)
Here is code inside "Plant Model" function:
function [A,B,C,D,U,Y,X,DX] = fcn(u,x)
% Sample time
Ts = 0.01;
% Model parameters
M = 1000; % Cart mass, kg
m = 800; % Load mass, kg
L = 3; % Reduced rope and load length, m
g = 9.81; % Gravity constant, m/s^2
k_cart = 0.0113; % Rolling resistance coefficient
R = 0.1; % Cart wheel radius, м
% Continuos-time model
% Calculated constants
c1 = 1 - m/(m + M);
c2 = -1/(L*(m + M));
Ac = [0 1 0 0
0 -k_cart*(m + M)*g/M m*g/M 0
0 0 0 1
0 k_cart*g/(L*c1) -g/(L*c1) 0];
Bc = [ 0
1/M
0
c2/c1];
Cc = [1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1];
Dc = [0
0
0
0];
% Generate discrete-time model
nx = size(Ac,1);
nu = size(Bc,2);
Mr = expm([[Ac Bc]*Ts; zeros(nu,nx+nu)]);
A = Mr(1:nx,1:nx);
B = Mr(1:nx,nx+1:nx+nu);
C = Cc;
D = Dc;
% Nominal conditions for discrete-time plant
X = x;
U = u;
Y = C*x + D*u;
DX = A*x+B*u-x;
0 个评论
回答(1 个)
Asvin Kumar
2021-3-17
The first assignment to an output variable determines its size in MATLAB Function blocks. I suppose Simulink isn't able to infer the size of A from its assignment statement.
Two ideas/suggestions:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear Plant Specification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!