# Block does not fully set the dimensions of output 'A'

조회 수: 4(최근 30일)
Aleksandr Kashirin 2021년 3월 15일
답변: Asvin Kumar 2021년 3월 17일
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'.
Does anyone know how to fix this?
Here is my sctructure:
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;

댓글을 달려면 로그인하십시오.

### 답변(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:
1. Try initializing A to zeros(4,4) or as appropriate.
2. 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.

댓글을 달려면 로그인하십시오.

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by