Simulink cannot determine sizes and/or types of the outputs for block 'MATLAB Function'
up vote
1
down vote
favorite
I have a small Simulink model as follows:
and the resepctive code:
function [xdot,y] = fcn(x,u)
% define your constants
g = 9.81;
m = 0.05;
R = 1;
L = 0.01;
C = 0.0001;
x1 = 0.012;
x2 = 0;
x3 = 0.84;
% nonlinear set of equations
xdot = [x2; g-((C/m)*(x3/x1)^2); -((R/L) +(((2*C)/L)*(((x2*x3)/((x1)^2)))))] + [0;0;1/L]*u;
y = x';
However when I try to run, Simulink generates the following errors:
Inferred size ('[1 3]') for data 'y' does not match specified size
('scalar'). Component:MATLAB Function | Category:Coder error Simulink
cannot determine sizes and/or types of the outputs for block 'MATLAB
Function' due to errors in the block body, or limitations of the
underlying analysis. The errors might be inaccurate. Fix the indicated
errors, or explicitly specify sizes and/or types for all block
outputs.
I searched through some documentation for variable size inputs and outputs, selected the variable size check box and also entered the upper bound as [1 3].
When I try to run again I get:
Expression '[1 3]' for maximum of data 'y' must evaluate to a scalar.
I'm not sure how to solve this error. I also looked here, but still couldn't get it to work.
Any help would be appreciated.
matlab simulink
add a comment |
up vote
1
down vote
favorite
I have a small Simulink model as follows:
and the resepctive code:
function [xdot,y] = fcn(x,u)
% define your constants
g = 9.81;
m = 0.05;
R = 1;
L = 0.01;
C = 0.0001;
x1 = 0.012;
x2 = 0;
x3 = 0.84;
% nonlinear set of equations
xdot = [x2; g-((C/m)*(x3/x1)^2); -((R/L) +(((2*C)/L)*(((x2*x3)/((x1)^2)))))] + [0;0;1/L]*u;
y = x';
However when I try to run, Simulink generates the following errors:
Inferred size ('[1 3]') for data 'y' does not match specified size
('scalar'). Component:MATLAB Function | Category:Coder error Simulink
cannot determine sizes and/or types of the outputs for block 'MATLAB
Function' due to errors in the block body, or limitations of the
underlying analysis. The errors might be inaccurate. Fix the indicated
errors, or explicitly specify sizes and/or types for all block
outputs.
I searched through some documentation for variable size inputs and outputs, selected the variable size check box and also entered the upper bound as [1 3].
When I try to run again I get:
Expression '[1 3]' for maximum of data 'y' must evaluate to a scalar.
I'm not sure how to solve this error. I also looked here, but still couldn't get it to work.
Any help would be appreciated.
matlab simulink
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a small Simulink model as follows:
and the resepctive code:
function [xdot,y] = fcn(x,u)
% define your constants
g = 9.81;
m = 0.05;
R = 1;
L = 0.01;
C = 0.0001;
x1 = 0.012;
x2 = 0;
x3 = 0.84;
% nonlinear set of equations
xdot = [x2; g-((C/m)*(x3/x1)^2); -((R/L) +(((2*C)/L)*(((x2*x3)/((x1)^2)))))] + [0;0;1/L]*u;
y = x';
However when I try to run, Simulink generates the following errors:
Inferred size ('[1 3]') for data 'y' does not match specified size
('scalar'). Component:MATLAB Function | Category:Coder error Simulink
cannot determine sizes and/or types of the outputs for block 'MATLAB
Function' due to errors in the block body, or limitations of the
underlying analysis. The errors might be inaccurate. Fix the indicated
errors, or explicitly specify sizes and/or types for all block
outputs.
I searched through some documentation for variable size inputs and outputs, selected the variable size check box and also entered the upper bound as [1 3].
When I try to run again I get:
Expression '[1 3]' for maximum of data 'y' must evaluate to a scalar.
I'm not sure how to solve this error. I also looked here, but still couldn't get it to work.
Any help would be appreciated.
matlab simulink
I have a small Simulink model as follows:
and the resepctive code:
function [xdot,y] = fcn(x,u)
% define your constants
g = 9.81;
m = 0.05;
R = 1;
L = 0.01;
C = 0.0001;
x1 = 0.012;
x2 = 0;
x3 = 0.84;
% nonlinear set of equations
xdot = [x2; g-((C/m)*(x3/x1)^2); -((R/L) +(((2*C)/L)*(((x2*x3)/((x1)^2)))))] + [0;0;1/L]*u;
y = x';
However when I try to run, Simulink generates the following errors:
Inferred size ('[1 3]') for data 'y' does not match specified size
('scalar'). Component:MATLAB Function | Category:Coder error Simulink
cannot determine sizes and/or types of the outputs for block 'MATLAB
Function' due to errors in the block body, or limitations of the
underlying analysis. The errors might be inaccurate. Fix the indicated
errors, or explicitly specify sizes and/or types for all block
outputs.
I searched through some documentation for variable size inputs and outputs, selected the variable size check box and also entered the upper bound as [1 3].
When I try to run again I get:
Expression '[1 3]' for maximum of data 'y' must evaluate to a scalar.
I'm not sure how to solve this error. I also looked here, but still couldn't get it to work.
Any help would be appreciated.
matlab simulink
matlab simulink
asked Nov 18 at 20:02
Rrz0
438518
438518
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
You'll probably find that your code will work by make the following changes,
You don't have variable sized data, and can set all of those options back to their default values.
(As indicated in one of the other answers, ) you need to change the way that the input
x
enters your equations because at the moment it does not get used to calculatexdot
.Move the
x1
,x2
andx3
to be the 3-by-1 vector of initial conditions for theIntegrator
block. (Assuming this is what they really are.)
With those changes the block should detect that the x
signal is a 3-by-1 (since the Integrator
block has 3 initial values), and hence your xdot
output is 3-by-1 and your y
output is 1-by-3.
To be on the safe side, you might also consider putting the following 2 lines at the top of your function.
xdot = zeros(3,1);
y = zeros(1,3);
Those lines will get used during block initialization to tell the compiler what the size of the output signals will be.
NOTE: why are you making y
a 1-by-3 vector? That's very unusual and I suspect you really want it to be a 3-by-1 vector (if you want to output the states) or you are supposed to sum up the values of x
to get y
in which case it is just a scalar.
Not related to the above, but you might also consider making your constants parameters of the block so that you can change them without editing the function.
add a comment |
up vote
2
down vote
I think you will have to set the set the sizes for all the inputs and outputs of the function block in the Ports and Data manager, like you tried.
Set the size for y
to [1 3]
, x
to [3 1]
and xdot
to [3 1]
.
Furthermore, I think that there is a mistake in your nonlinear state space, since your 'A' matrix is now constant. So to make them dependent on the current state, replace the declaration of x1
etc to:
x1 = x(1);
x2 = x(2);
x3 = x(3);
I assume that the values you have there right now are your initial conditions for the differential equations, which you will have to set in the integrator block .
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You'll probably find that your code will work by make the following changes,
You don't have variable sized data, and can set all of those options back to their default values.
(As indicated in one of the other answers, ) you need to change the way that the input
x
enters your equations because at the moment it does not get used to calculatexdot
.Move the
x1
,x2
andx3
to be the 3-by-1 vector of initial conditions for theIntegrator
block. (Assuming this is what they really are.)
With those changes the block should detect that the x
signal is a 3-by-1 (since the Integrator
block has 3 initial values), and hence your xdot
output is 3-by-1 and your y
output is 1-by-3.
To be on the safe side, you might also consider putting the following 2 lines at the top of your function.
xdot = zeros(3,1);
y = zeros(1,3);
Those lines will get used during block initialization to tell the compiler what the size of the output signals will be.
NOTE: why are you making y
a 1-by-3 vector? That's very unusual and I suspect you really want it to be a 3-by-1 vector (if you want to output the states) or you are supposed to sum up the values of x
to get y
in which case it is just a scalar.
Not related to the above, but you might also consider making your constants parameters of the block so that you can change them without editing the function.
add a comment |
up vote
3
down vote
accepted
You'll probably find that your code will work by make the following changes,
You don't have variable sized data, and can set all of those options back to their default values.
(As indicated in one of the other answers, ) you need to change the way that the input
x
enters your equations because at the moment it does not get used to calculatexdot
.Move the
x1
,x2
andx3
to be the 3-by-1 vector of initial conditions for theIntegrator
block. (Assuming this is what they really are.)
With those changes the block should detect that the x
signal is a 3-by-1 (since the Integrator
block has 3 initial values), and hence your xdot
output is 3-by-1 and your y
output is 1-by-3.
To be on the safe side, you might also consider putting the following 2 lines at the top of your function.
xdot = zeros(3,1);
y = zeros(1,3);
Those lines will get used during block initialization to tell the compiler what the size of the output signals will be.
NOTE: why are you making y
a 1-by-3 vector? That's very unusual and I suspect you really want it to be a 3-by-1 vector (if you want to output the states) or you are supposed to sum up the values of x
to get y
in which case it is just a scalar.
Not related to the above, but you might also consider making your constants parameters of the block so that you can change them without editing the function.
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You'll probably find that your code will work by make the following changes,
You don't have variable sized data, and can set all of those options back to their default values.
(As indicated in one of the other answers, ) you need to change the way that the input
x
enters your equations because at the moment it does not get used to calculatexdot
.Move the
x1
,x2
andx3
to be the 3-by-1 vector of initial conditions for theIntegrator
block. (Assuming this is what they really are.)
With those changes the block should detect that the x
signal is a 3-by-1 (since the Integrator
block has 3 initial values), and hence your xdot
output is 3-by-1 and your y
output is 1-by-3.
To be on the safe side, you might also consider putting the following 2 lines at the top of your function.
xdot = zeros(3,1);
y = zeros(1,3);
Those lines will get used during block initialization to tell the compiler what the size of the output signals will be.
NOTE: why are you making y
a 1-by-3 vector? That's very unusual and I suspect you really want it to be a 3-by-1 vector (if you want to output the states) or you are supposed to sum up the values of x
to get y
in which case it is just a scalar.
Not related to the above, but you might also consider making your constants parameters of the block so that you can change them without editing the function.
You'll probably find that your code will work by make the following changes,
You don't have variable sized data, and can set all of those options back to their default values.
(As indicated in one of the other answers, ) you need to change the way that the input
x
enters your equations because at the moment it does not get used to calculatexdot
.Move the
x1
,x2
andx3
to be the 3-by-1 vector of initial conditions for theIntegrator
block. (Assuming this is what they really are.)
With those changes the block should detect that the x
signal is a 3-by-1 (since the Integrator
block has 3 initial values), and hence your xdot
output is 3-by-1 and your y
output is 1-by-3.
To be on the safe side, you might also consider putting the following 2 lines at the top of your function.
xdot = zeros(3,1);
y = zeros(1,3);
Those lines will get used during block initialization to tell the compiler what the size of the output signals will be.
NOTE: why are you making y
a 1-by-3 vector? That's very unusual and I suspect you really want it to be a 3-by-1 vector (if you want to output the states) or you are supposed to sum up the values of x
to get y
in which case it is just a scalar.
Not related to the above, but you might also consider making your constants parameters of the block so that you can change them without editing the function.
edited Nov 18 at 22:32
answered Nov 18 at 22:15
Phil Goddard
8,4871723
8,4871723
add a comment |
add a comment |
up vote
2
down vote
I think you will have to set the set the sizes for all the inputs and outputs of the function block in the Ports and Data manager, like you tried.
Set the size for y
to [1 3]
, x
to [3 1]
and xdot
to [3 1]
.
Furthermore, I think that there is a mistake in your nonlinear state space, since your 'A' matrix is now constant. So to make them dependent on the current state, replace the declaration of x1
etc to:
x1 = x(1);
x2 = x(2);
x3 = x(3);
I assume that the values you have there right now are your initial conditions for the differential equations, which you will have to set in the integrator block .
add a comment |
up vote
2
down vote
I think you will have to set the set the sizes for all the inputs and outputs of the function block in the Ports and Data manager, like you tried.
Set the size for y
to [1 3]
, x
to [3 1]
and xdot
to [3 1]
.
Furthermore, I think that there is a mistake in your nonlinear state space, since your 'A' matrix is now constant. So to make them dependent on the current state, replace the declaration of x1
etc to:
x1 = x(1);
x2 = x(2);
x3 = x(3);
I assume that the values you have there right now are your initial conditions for the differential equations, which you will have to set in the integrator block .
add a comment |
up vote
2
down vote
up vote
2
down vote
I think you will have to set the set the sizes for all the inputs and outputs of the function block in the Ports and Data manager, like you tried.
Set the size for y
to [1 3]
, x
to [3 1]
and xdot
to [3 1]
.
Furthermore, I think that there is a mistake in your nonlinear state space, since your 'A' matrix is now constant. So to make them dependent on the current state, replace the declaration of x1
etc to:
x1 = x(1);
x2 = x(2);
x3 = x(3);
I assume that the values you have there right now are your initial conditions for the differential equations, which you will have to set in the integrator block .
I think you will have to set the set the sizes for all the inputs and outputs of the function block in the Ports and Data manager, like you tried.
Set the size for y
to [1 3]
, x
to [3 1]
and xdot
to [3 1]
.
Furthermore, I think that there is a mistake in your nonlinear state space, since your 'A' matrix is now constant. So to make them dependent on the current state, replace the declaration of x1
etc to:
x1 = x(1);
x2 = x(2);
x3 = x(3);
I assume that the values you have there right now are your initial conditions for the differential equations, which you will have to set in the integrator block .
answered Nov 18 at 21:13
rinkert
1,092316
1,092316
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364909%2fsimulink-cannot-determine-sizes-and-or-types-of-the-outputs-for-block-matlab-fu%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown