what does an equality inside a plot function in MATLAB mean?












1















So I´m just new on MATLAB and this may be a very silly doubt but when generating basic signals for signal processing I have this:



t = (-1:0.01:1)';



impulse = t==0;
plot(t,impulse)



(from: https://www.mathworks.com/help/signal/gs/impulse-step-and-ramp-functions.html)



So I know that will plot a unit impulse yet I can't see what t==0 is doing there. AT time instant = 0 it will go up to 1, as expected, but why?
More specifically, can anyone explain me what the "==" is telling MATLAB to do?



Thank you so much










share|improve this question



























    1















    So I´m just new on MATLAB and this may be a very silly doubt but when generating basic signals for signal processing I have this:



    t = (-1:0.01:1)';



    impulse = t==0;
    plot(t,impulse)



    (from: https://www.mathworks.com/help/signal/gs/impulse-step-and-ramp-functions.html)



    So I know that will plot a unit impulse yet I can't see what t==0 is doing there. AT time instant = 0 it will go up to 1, as expected, but why?
    More specifically, can anyone explain me what the "==" is telling MATLAB to do?



    Thank you so much










    share|improve this question

























      1












      1








      1








      So I´m just new on MATLAB and this may be a very silly doubt but when generating basic signals for signal processing I have this:



      t = (-1:0.01:1)';



      impulse = t==0;
      plot(t,impulse)



      (from: https://www.mathworks.com/help/signal/gs/impulse-step-and-ramp-functions.html)



      So I know that will plot a unit impulse yet I can't see what t==0 is doing there. AT time instant = 0 it will go up to 1, as expected, but why?
      More specifically, can anyone explain me what the "==" is telling MATLAB to do?



      Thank you so much










      share|improve this question














      So I´m just new on MATLAB and this may be a very silly doubt but when generating basic signals for signal processing I have this:



      t = (-1:0.01:1)';



      impulse = t==0;
      plot(t,impulse)



      (from: https://www.mathworks.com/help/signal/gs/impulse-step-and-ramp-functions.html)



      So I know that will plot a unit impulse yet I can't see what t==0 is doing there. AT time instant = 0 it will go up to 1, as expected, but why?
      More specifically, can anyone explain me what the "==" is telling MATLAB to do?



      Thank you so much







      matlab signal processing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 25 at 17:06









      PabloPablo

      102




      102






















          1 Answer
          1






          active

          oldest

          votes


















          0














          In most programming languages you can take the expression that is fit for an "if" statement and use it in any calculation.



          In most cases, when the expression is "TRUE", it will give the value "1" as result.



          Therefore "t==0" evaluates to "1" when the value of "t" is zero (0)... in any other cases the result is zero.



          This makes it possible to write code without "if"-statements that behaves the same as code using one or more if statements.



          e.g.




          $ python
          Python 2.7.12 (default, Nov 12 2018, 14:36:49)
          [GCC 5.4.0 20160609] on linux2
          Type "help", "copyright", "credits" or "license" for more information.
          >>> for x in xrange(0,20):
          ... print (x!=10)*x,
          ...
          0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19
          >>> for x in xrange(0,20):
          ... if x!=10:
          ... print x,
          ... else:
          ... print 0,
          ...
          0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19
          >>> quit()
          $





          share|improve this answer


























          • Great answer Hannu. Muchas gracias!

            – Pablo
            Jan 26 at 11:44











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          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%2fsuperuser.com%2fquestions%2f1398479%2fwhat-does-an-equality-inside-a-plot-function-in-matlab-mean%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









          0














          In most programming languages you can take the expression that is fit for an "if" statement and use it in any calculation.



          In most cases, when the expression is "TRUE", it will give the value "1" as result.



          Therefore "t==0" evaluates to "1" when the value of "t" is zero (0)... in any other cases the result is zero.



          This makes it possible to write code without "if"-statements that behaves the same as code using one or more if statements.



          e.g.




          $ python
          Python 2.7.12 (default, Nov 12 2018, 14:36:49)
          [GCC 5.4.0 20160609] on linux2
          Type "help", "copyright", "credits" or "license" for more information.
          >>> for x in xrange(0,20):
          ... print (x!=10)*x,
          ...
          0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19
          >>> for x in xrange(0,20):
          ... if x!=10:
          ... print x,
          ... else:
          ... print 0,
          ...
          0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19
          >>> quit()
          $





          share|improve this answer


























          • Great answer Hannu. Muchas gracias!

            – Pablo
            Jan 26 at 11:44
















          0














          In most programming languages you can take the expression that is fit for an "if" statement and use it in any calculation.



          In most cases, when the expression is "TRUE", it will give the value "1" as result.



          Therefore "t==0" evaluates to "1" when the value of "t" is zero (0)... in any other cases the result is zero.



          This makes it possible to write code without "if"-statements that behaves the same as code using one or more if statements.



          e.g.




          $ python
          Python 2.7.12 (default, Nov 12 2018, 14:36:49)
          [GCC 5.4.0 20160609] on linux2
          Type "help", "copyright", "credits" or "license" for more information.
          >>> for x in xrange(0,20):
          ... print (x!=10)*x,
          ...
          0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19
          >>> for x in xrange(0,20):
          ... if x!=10:
          ... print x,
          ... else:
          ... print 0,
          ...
          0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19
          >>> quit()
          $





          share|improve this answer


























          • Great answer Hannu. Muchas gracias!

            – Pablo
            Jan 26 at 11:44














          0












          0








          0







          In most programming languages you can take the expression that is fit for an "if" statement and use it in any calculation.



          In most cases, when the expression is "TRUE", it will give the value "1" as result.



          Therefore "t==0" evaluates to "1" when the value of "t" is zero (0)... in any other cases the result is zero.



          This makes it possible to write code without "if"-statements that behaves the same as code using one or more if statements.



          e.g.




          $ python
          Python 2.7.12 (default, Nov 12 2018, 14:36:49)
          [GCC 5.4.0 20160609] on linux2
          Type "help", "copyright", "credits" or "license" for more information.
          >>> for x in xrange(0,20):
          ... print (x!=10)*x,
          ...
          0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19
          >>> for x in xrange(0,20):
          ... if x!=10:
          ... print x,
          ... else:
          ... print 0,
          ...
          0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19
          >>> quit()
          $





          share|improve this answer















          In most programming languages you can take the expression that is fit for an "if" statement and use it in any calculation.



          In most cases, when the expression is "TRUE", it will give the value "1" as result.



          Therefore "t==0" evaluates to "1" when the value of "t" is zero (0)... in any other cases the result is zero.



          This makes it possible to write code without "if"-statements that behaves the same as code using one or more if statements.



          e.g.




          $ python
          Python 2.7.12 (default, Nov 12 2018, 14:36:49)
          [GCC 5.4.0 20160609] on linux2
          Type "help", "copyright", "credits" or "license" for more information.
          >>> for x in xrange(0,20):
          ... print (x!=10)*x,
          ...
          0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19
          >>> for x in xrange(0,20):
          ... if x!=10:
          ... print x,
          ... else:
          ... print 0,
          ...
          0 1 2 3 4 5 6 7 8 9 0 11 12 13 14 15 16 17 18 19
          >>> quit()
          $






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 1 at 4:59

























          answered Jan 25 at 20:34









          HannuHannu

          4,1451925




          4,1451925













          • Great answer Hannu. Muchas gracias!

            – Pablo
            Jan 26 at 11:44



















          • Great answer Hannu. Muchas gracias!

            – Pablo
            Jan 26 at 11:44

















          Great answer Hannu. Muchas gracias!

          – Pablo
          Jan 26 at 11:44





          Great answer Hannu. Muchas gracias!

          – Pablo
          Jan 26 at 11:44


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • 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%2fsuperuser.com%2fquestions%2f1398479%2fwhat-does-an-equality-inside-a-plot-function-in-matlab-mean%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

          flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

          Mangá

          Eduardo VII do Reino Unido