# Simulink considers that an output matrix has variable size when the size is always constant

18 visualizaciones (últimos 30 días)
Inés Deiros Gras el 12 de Mayo de 2024
Comentada: Inés Deiros Gras el 20 de Mayo de 2024 a las 9:33
Hi! I'm running a code in simulink (in one of the matlab function blocks) and I keep getting errors regarding the size of the output matrix. My code is the following one, where phi_1 is a ramp input that goes from 0 to 2*pi, and all the values in perm are constants:
function Ga = G(phi_1,perm)
G_amax=perm(1);
n=perm(2);
ns=perm(5);
nr=perm(6);
gamma=perm(3);
gammap=perm(4);
Ga=zeros(nr,ns);
%define angles between rotor (rows) and stator (columns) teeth
phi=zeros(nr,ns);
phi(1,1)=phi_1;
phi(2,1)=phi(1,1) + 2*pi/nr;
for j=2:ns
phi(1,j)=phi(1,j-1) - 2*pi/ns;
phi(2,j)=phi(1,j) + 2*pi/nr;
end
%make sure that the angle is in the first fifth (it's periodic every 1/5th
%of a turn)
for j=1:nr
for k=1:ns
while phi(j,k)<0
phi(j,k)=phi(j,k)+2*pi;
end
while phi(j,k)>2*pi/5
phi(j,k)=phi(j,k)-2*pi/5;
end
%permeances as a function of the angle
if 0<=phi(k,j) && phi(k,j)<gammap || 2*pi/n - gammap<=phi(k,j) && phi(k,j)<=2*pi/n
Ga(k,j)=G_amax;
elseif gammap<=phi(k,j) && phi(k,j)<=gamma
Ga(k,j)=G_amax/2 * (1+cos(pi*(phi(k,j)-gammap)/(gamma-gammap)));
elseif 2*pi/n - gamma<=phi(k,j) && phi(k,j)<=2*pi/n - gammap
Ga(k,j)=G_amax/2 * (1+cos(pi*(phi(k,j)-2*pi/n+gammap)/(gamma-gammap)));
else
Ga(k,j)=0;
end
end
end
When I run the simulation, I get the following error:
Error:A signal of unbounded array type is not supported on 'Input Port 1' of block 'air_gap/Scope2'. For a list of supported data types, see the block documentation page.
If I try setting the size of the matrix Ga to the one that it's supposed to have ([2,3]) in the explore section instead of the predetermined -1, I get this error:
Error:The signal at 'Output Port 1' of 'air_gap/MATLAB Function2' is a variable-size signal with a nondiscrete sample time. The sample time for any variable-size signal must be discrete.
However, I want to be able to use continuous signals instead of discrete ones. Is there a way to do so? And if not, how do I switch it to discrete?
Thanks!
##### 2 comentariosMostrar NingunoOcultar Ninguno
Fangjun Jiang el 13 de Mayo de 2024
What is "perm"? An input to the MATLAB Function block?
Inés Deiros Gras el 13 de Mayo de 2024
Perm is just a matrix I defined in MATLAB and inputed as a constant block. It is defined as follows:
Gamax=10;
n=5;
nr=2;
ns=3;
gamma=3*pi/15;
gammap=gamma/2;
perm=[Gamax,n,gamma,gammap,ns,nr];

Iniciar sesión para comentar.

### Respuestas (1)

Fangjun Jiang el 14 de Mayo de 2024
Editada: Fangjun Jiang el 14 de Mayo de 2024
You have "Ga=zeros(nr,ns)" so the size of Ga is fixed in your mind. But it is not the case for Simulink. Since nr and ns all come from input. Their value could change during simulation thus the size of Ga could be varying.
In the MATLAB Function block, change the scope of "perm" from "Input" to "Parameter". It will still appear in the function code input argument, but it will not appear as an input port in the MATLAB Function block. Define "perm" in the base workspace.
Hopefully, that will fixed the "variable size" error.
##### 5 comentariosMostrar 3 comentarios más antiguosOcultar 3 comentarios más antiguos
Fangjun Jiang el 16 de Mayo de 2024 a las 16:54
no error at all.
Inés Deiros Gras el 20 de Mayo de 2024 a las 9:33
Thank you very much!! I don't know what I was doing before, but I started a new file and now it works. Thanks a lot!!!

Iniciar sesión para comentar.

### Categorías

Más información sobre Sources en Help Center y File Exchange.

R2023b

### Community Treasure Hunt

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

Start Hunting!

Translated by