Simulink considers that an output matrix has variable size when the size is always constant
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!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! 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! simulink, variable-size, signal size, simulation, error, workspace MATLAB Answers — New Questions