Use the Output as the New Input into Matlab Function block in Simulink












1














I have three inputs into a Matlab Function block in my Simulink Model. The inputs consist of a 1D array thetaArray and two variables currentIndex and trackingError. The Matlab Function block will output two variables called newIndex and theta.



What would be an ideal way to use the newIndex variable as my new input into the Matlab Function block?



Here is the image of my Simulink Model



And here is the code for the Matlab Function Block in the model:



function [newIndex,theta] = arraySelector(thetaArray,currentIndex,trackingError)

if currentIndex < length(thetaArray) && trackingError <= 0.00002
newIndex = currentIndex + 1;
else
newIndex = currentIndex;
end

theta = thetaArray(newIndex);
end


Thank you in advance.










share|improve this question


















  • 3




    Send it back through a unit delay block.
    – Navan
    Nov 20 at 13:15
















1














I have three inputs into a Matlab Function block in my Simulink Model. The inputs consist of a 1D array thetaArray and two variables currentIndex and trackingError. The Matlab Function block will output two variables called newIndex and theta.



What would be an ideal way to use the newIndex variable as my new input into the Matlab Function block?



Here is the image of my Simulink Model



And here is the code for the Matlab Function Block in the model:



function [newIndex,theta] = arraySelector(thetaArray,currentIndex,trackingError)

if currentIndex < length(thetaArray) && trackingError <= 0.00002
newIndex = currentIndex + 1;
else
newIndex = currentIndex;
end

theta = thetaArray(newIndex);
end


Thank you in advance.










share|improve this question


















  • 3




    Send it back through a unit delay block.
    – Navan
    Nov 20 at 13:15














1












1








1







I have three inputs into a Matlab Function block in my Simulink Model. The inputs consist of a 1D array thetaArray and two variables currentIndex and trackingError. The Matlab Function block will output two variables called newIndex and theta.



What would be an ideal way to use the newIndex variable as my new input into the Matlab Function block?



Here is the image of my Simulink Model



And here is the code for the Matlab Function Block in the model:



function [newIndex,theta] = arraySelector(thetaArray,currentIndex,trackingError)

if currentIndex < length(thetaArray) && trackingError <= 0.00002
newIndex = currentIndex + 1;
else
newIndex = currentIndex;
end

theta = thetaArray(newIndex);
end


Thank you in advance.










share|improve this question













I have three inputs into a Matlab Function block in my Simulink Model. The inputs consist of a 1D array thetaArray and two variables currentIndex and trackingError. The Matlab Function block will output two variables called newIndex and theta.



What would be an ideal way to use the newIndex variable as my new input into the Matlab Function block?



Here is the image of my Simulink Model



And here is the code for the Matlab Function Block in the model:



function [newIndex,theta] = arraySelector(thetaArray,currentIndex,trackingError)

if currentIndex < length(thetaArray) && trackingError <= 0.00002
newIndex = currentIndex + 1;
else
newIndex = currentIndex;
end

theta = thetaArray(newIndex);
end


Thank you in advance.







matlab simulink






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 7:35









dekaranger00

61




61








  • 3




    Send it back through a unit delay block.
    – Navan
    Nov 20 at 13:15














  • 3




    Send it back through a unit delay block.
    – Navan
    Nov 20 at 13:15








3




3




Send it back through a unit delay block.
– Navan
Nov 20 at 13:15




Send it back through a unit delay block.
– Navan
Nov 20 at 13:15












1 Answer
1






active

oldest

votes


















2














If theta will be the output and the input of the model you will have a model which contains an
algebraic loop.



It is unclear from your question if you




  1. need to solve the algebraic loop within a single time step OR

  2. you want your model advance in time with each iteration of the loop.


For 2nd case:



This is the easier case. (more likely when studying your model). Here you will break the loop e.g. by introducing a delay block. The initial condition of the delay block will be what you have now defined in the example (block theta_1).



For 1st case:



Follow the description in How to Handle Algebraic Loops in a Model. I would recommend that you first study with an example where you use a scalar instead of an array. You need to define the initial condition for the index, e.g. by introducing an IC-Block (like you did for the trackingerror) into the loop. If simulink is still unable to solve the algebraic loop consider an alternative implementation inside your Matlab Function Block which changes the status of your input .
from direct feedthrough to non-direct feedthrough






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',
    autoActivateHeartbeat: false,
    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%2f53388229%2fuse-the-output-as-the-new-input-into-matlab-function-block-in-simulink%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    If theta will be the output and the input of the model you will have a model which contains an
    algebraic loop.



    It is unclear from your question if you




    1. need to solve the algebraic loop within a single time step OR

    2. you want your model advance in time with each iteration of the loop.


    For 2nd case:



    This is the easier case. (more likely when studying your model). Here you will break the loop e.g. by introducing a delay block. The initial condition of the delay block will be what you have now defined in the example (block theta_1).



    For 1st case:



    Follow the description in How to Handle Algebraic Loops in a Model. I would recommend that you first study with an example where you use a scalar instead of an array. You need to define the initial condition for the index, e.g. by introducing an IC-Block (like you did for the trackingerror) into the loop. If simulink is still unable to solve the algebraic loop consider an alternative implementation inside your Matlab Function Block which changes the status of your input .
    from direct feedthrough to non-direct feedthrough






    share|improve this answer


























      2














      If theta will be the output and the input of the model you will have a model which contains an
      algebraic loop.



      It is unclear from your question if you




      1. need to solve the algebraic loop within a single time step OR

      2. you want your model advance in time with each iteration of the loop.


      For 2nd case:



      This is the easier case. (more likely when studying your model). Here you will break the loop e.g. by introducing a delay block. The initial condition of the delay block will be what you have now defined in the example (block theta_1).



      For 1st case:



      Follow the description in How to Handle Algebraic Loops in a Model. I would recommend that you first study with an example where you use a scalar instead of an array. You need to define the initial condition for the index, e.g. by introducing an IC-Block (like you did for the trackingerror) into the loop. If simulink is still unable to solve the algebraic loop consider an alternative implementation inside your Matlab Function Block which changes the status of your input .
      from direct feedthrough to non-direct feedthrough






      share|improve this answer
























        2












        2








        2






        If theta will be the output and the input of the model you will have a model which contains an
        algebraic loop.



        It is unclear from your question if you




        1. need to solve the algebraic loop within a single time step OR

        2. you want your model advance in time with each iteration of the loop.


        For 2nd case:



        This is the easier case. (more likely when studying your model). Here you will break the loop e.g. by introducing a delay block. The initial condition of the delay block will be what you have now defined in the example (block theta_1).



        For 1st case:



        Follow the description in How to Handle Algebraic Loops in a Model. I would recommend that you first study with an example where you use a scalar instead of an array. You need to define the initial condition for the index, e.g. by introducing an IC-Block (like you did for the trackingerror) into the loop. If simulink is still unable to solve the algebraic loop consider an alternative implementation inside your Matlab Function Block which changes the status of your input .
        from direct feedthrough to non-direct feedthrough






        share|improve this answer












        If theta will be the output and the input of the model you will have a model which contains an
        algebraic loop.



        It is unclear from your question if you




        1. need to solve the algebraic loop within a single time step OR

        2. you want your model advance in time with each iteration of the loop.


        For 2nd case:



        This is the easier case. (more likely when studying your model). Here you will break the loop e.g. by introducing a delay block. The initial condition of the delay block will be what you have now defined in the example (block theta_1).



        For 1st case:



        Follow the description in How to Handle Algebraic Loops in a Model. I would recommend that you first study with an example where you use a scalar instead of an array. You need to define the initial condition for the index, e.g. by introducing an IC-Block (like you did for the trackingerror) into the loop. If simulink is still unable to solve the algebraic loop consider an alternative implementation inside your Matlab Function Block which changes the status of your input .
        from direct feedthrough to non-direct feedthrough







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 at 14:12









        ToBe

        4041418




        4041418






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388229%2fuse-the-output-as-the-new-input-into-matlab-function-block-in-simulink%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

            If I really need a card on my start hand, how many mulligans make sense? [duplicate]

            Alcedinidae

            Can an atomic nucleus contain both particles and antiparticles? [duplicate]