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:



enter image description here



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.










share|improve this question


























    up vote
    1
    down vote

    favorite












    I have a small Simulink model as follows:



    enter image description here



    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.










    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a small Simulink model as follows:



      enter image description here



      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.










      share|improve this question













      I have a small Simulink model as follows:



      enter image description here



      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 at 20:02









      Rrz0

      438518




      438518
























          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 calculate xdot.


          • Move the x1, x2 and x3 to be the 3-by-1 vector of initial conditions for the Integrator 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.






          share|improve this answer






























            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 .






            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              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

























              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 calculate xdot.


              • Move the x1, x2 and x3 to be the 3-by-1 vector of initial conditions for the Integrator 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.






              share|improve this answer



























                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 calculate xdot.


                • Move the x1, x2 and x3 to be the 3-by-1 vector of initial conditions for the Integrator 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.






                share|improve this answer

























                  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 calculate xdot.


                  • Move the x1, x2 and x3 to be the 3-by-1 vector of initial conditions for the Integrator 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.






                  share|improve this answer














                  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 calculate xdot.


                  • Move the x1, x2 and x3 to be the 3-by-1 vector of initial conditions for the Integrator 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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 18 at 22:32

























                  answered Nov 18 at 22:15









                  Phil Goddard

                  8,4871723




                  8,4871723
























                      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 .






                      share|improve this answer

























                        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 .






                        share|improve this answer























                          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 .






                          share|improve this answer












                          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 .







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 18 at 21:13









                          rinkert

                          1,092316




                          1,092316






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Costa Masnaga

                              Fotorealismo

                              Sidney Franklin