Something strange using polar plot function in MATLAB












1















I have a simple function of theta and I want to plot this function in dB using the polarplot function in MATLAB. But when I make the graph from -40 to 0, the graph seems to have a strange part around horizontal axis. My MATLAB code (R2016a) is:



%% Define range of plotting angle.
ceta= [10^-9:0.0001:2*pi];
% ceta starts not from pure zero to avoid 0/0 in some cases.

E = abs( ( cos((cos(ceta))*pi/2) ) ./ ( sin(ceta) ) );

power_dB = 10.*log10(E.^2);
power_dB = power_dB - max(power_dB);
max(power_dB)
polarplot(ceta,power_dB);
rlim([-40 0]);


The obtained figure is this:
plot resulting from code










share|improve this question





























    1















    I have a simple function of theta and I want to plot this function in dB using the polarplot function in MATLAB. But when I make the graph from -40 to 0, the graph seems to have a strange part around horizontal axis. My MATLAB code (R2016a) is:



    %% Define range of plotting angle.
    ceta= [10^-9:0.0001:2*pi];
    % ceta starts not from pure zero to avoid 0/0 in some cases.

    E = abs( ( cos((cos(ceta))*pi/2) ) ./ ( sin(ceta) ) );

    power_dB = 10.*log10(E.^2);
    power_dB = power_dB - max(power_dB);
    max(power_dB)
    polarplot(ceta,power_dB);
    rlim([-40 0]);


    The obtained figure is this:
    plot resulting from code










    share|improve this question



























      1












      1








      1


      0






      I have a simple function of theta and I want to plot this function in dB using the polarplot function in MATLAB. But when I make the graph from -40 to 0, the graph seems to have a strange part around horizontal axis. My MATLAB code (R2016a) is:



      %% Define range of plotting angle.
      ceta= [10^-9:0.0001:2*pi];
      % ceta starts not from pure zero to avoid 0/0 in some cases.

      E = abs( ( cos((cos(ceta))*pi/2) ) ./ ( sin(ceta) ) );

      power_dB = 10.*log10(E.^2);
      power_dB = power_dB - max(power_dB);
      max(power_dB)
      polarplot(ceta,power_dB);
      rlim([-40 0]);


      The obtained figure is this:
      plot resulting from code










      share|improve this question
















      I have a simple function of theta and I want to plot this function in dB using the polarplot function in MATLAB. But when I make the graph from -40 to 0, the graph seems to have a strange part around horizontal axis. My MATLAB code (R2016a) is:



      %% Define range of plotting angle.
      ceta= [10^-9:0.0001:2*pi];
      % ceta starts not from pure zero to avoid 0/0 in some cases.

      E = abs( ( cos((cos(ceta))*pi/2) ) ./ ( sin(ceta) ) );

      power_dB = 10.*log10(E.^2);
      power_dB = power_dB - max(power_dB);
      max(power_dB)
      polarplot(ceta,power_dB);
      rlim([-40 0]);


      The obtained figure is this:
      plot resulting from code







      matlab plot polar-coordinates






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 23:29









      Cris Luengo

      19.3k51947




      19.3k51947










      asked Nov 19 '18 at 22:56









      user288086user288086

      134




      134
























          1 Answer
          1






          active

          oldest

          votes


















          4














          Your values for E are very near to 0 when ceta = 0, pi, or 2pi. This is resulting in very large values when you take the log of E.



          You can just remove the points from ceta and E when E is very low. See the code block below.



          E =  abs( (  cos((cos(ceta))*pi/2) ) ./ ( sin(ceta) ) ); 
          ceta(E<1e-2) = ;
          E(E<1e-2) = ;
          power_dB = 10.*log10(E.^2);
          power_dB = power_dB - max(power_dB);
          max(power_dB)
          polarplot(ceta,power_dB);
          rlim([-40 0]);


          Gives:



          enter image description here






          share|improve this answer
























          • i have a question, when 10*log10(E.^2) tends to large value i think rlim([ -40 0]) should remove it so why that is not happened?

            – user288086
            Nov 19 '18 at 23:31













          • rlim is only controlling the figure axis. What's happening is as you plot value larger than -40 (in terms of magnitude) its passing through the origin and continuing to the edges of the plot. Try this, remove the line I suggested and add in power_dB(power_dB < -60) = -60 right before your polar plot. You'll see the lines come back, but stop at 2 circles out from the center. This represents the -60 value once they've passed through the origin.

            – Matt
            Nov 19 '18 at 23:44













          • Also, looking at this a second time better solution might have been to just use power_dB(power_dB < -40) = -40, rather than my suggested change.

            – Matt
            Nov 19 '18 at 23:45











          • E = abs(cos(cos(ceta)*pi/2) ./ sin(ceta)); would suffice, cutting down on the LISP style usage of brackets.

            – Adriaan
            Nov 30 '18 at 22:21











          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%2f53383828%2fsomething-strange-using-polar-plot-function-in-matlab%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









          4














          Your values for E are very near to 0 when ceta = 0, pi, or 2pi. This is resulting in very large values when you take the log of E.



          You can just remove the points from ceta and E when E is very low. See the code block below.



          E =  abs( (  cos((cos(ceta))*pi/2) ) ./ ( sin(ceta) ) ); 
          ceta(E<1e-2) = ;
          E(E<1e-2) = ;
          power_dB = 10.*log10(E.^2);
          power_dB = power_dB - max(power_dB);
          max(power_dB)
          polarplot(ceta,power_dB);
          rlim([-40 0]);


          Gives:



          enter image description here






          share|improve this answer
























          • i have a question, when 10*log10(E.^2) tends to large value i think rlim([ -40 0]) should remove it so why that is not happened?

            – user288086
            Nov 19 '18 at 23:31













          • rlim is only controlling the figure axis. What's happening is as you plot value larger than -40 (in terms of magnitude) its passing through the origin and continuing to the edges of the plot. Try this, remove the line I suggested and add in power_dB(power_dB < -60) = -60 right before your polar plot. You'll see the lines come back, but stop at 2 circles out from the center. This represents the -60 value once they've passed through the origin.

            – Matt
            Nov 19 '18 at 23:44













          • Also, looking at this a second time better solution might have been to just use power_dB(power_dB < -40) = -40, rather than my suggested change.

            – Matt
            Nov 19 '18 at 23:45











          • E = abs(cos(cos(ceta)*pi/2) ./ sin(ceta)); would suffice, cutting down on the LISP style usage of brackets.

            – Adriaan
            Nov 30 '18 at 22:21
















          4














          Your values for E are very near to 0 when ceta = 0, pi, or 2pi. This is resulting in very large values when you take the log of E.



          You can just remove the points from ceta and E when E is very low. See the code block below.



          E =  abs( (  cos((cos(ceta))*pi/2) ) ./ ( sin(ceta) ) ); 
          ceta(E<1e-2) = ;
          E(E<1e-2) = ;
          power_dB = 10.*log10(E.^2);
          power_dB = power_dB - max(power_dB);
          max(power_dB)
          polarplot(ceta,power_dB);
          rlim([-40 0]);


          Gives:



          enter image description here






          share|improve this answer
























          • i have a question, when 10*log10(E.^2) tends to large value i think rlim([ -40 0]) should remove it so why that is not happened?

            – user288086
            Nov 19 '18 at 23:31













          • rlim is only controlling the figure axis. What's happening is as you plot value larger than -40 (in terms of magnitude) its passing through the origin and continuing to the edges of the plot. Try this, remove the line I suggested and add in power_dB(power_dB < -60) = -60 right before your polar plot. You'll see the lines come back, but stop at 2 circles out from the center. This represents the -60 value once they've passed through the origin.

            – Matt
            Nov 19 '18 at 23:44













          • Also, looking at this a second time better solution might have been to just use power_dB(power_dB < -40) = -40, rather than my suggested change.

            – Matt
            Nov 19 '18 at 23:45











          • E = abs(cos(cos(ceta)*pi/2) ./ sin(ceta)); would suffice, cutting down on the LISP style usage of brackets.

            – Adriaan
            Nov 30 '18 at 22:21














          4












          4








          4







          Your values for E are very near to 0 when ceta = 0, pi, or 2pi. This is resulting in very large values when you take the log of E.



          You can just remove the points from ceta and E when E is very low. See the code block below.



          E =  abs( (  cos((cos(ceta))*pi/2) ) ./ ( sin(ceta) ) ); 
          ceta(E<1e-2) = ;
          E(E<1e-2) = ;
          power_dB = 10.*log10(E.^2);
          power_dB = power_dB - max(power_dB);
          max(power_dB)
          polarplot(ceta,power_dB);
          rlim([-40 0]);


          Gives:



          enter image description here






          share|improve this answer













          Your values for E are very near to 0 when ceta = 0, pi, or 2pi. This is resulting in very large values when you take the log of E.



          You can just remove the points from ceta and E when E is very low. See the code block below.



          E =  abs( (  cos((cos(ceta))*pi/2) ) ./ ( sin(ceta) ) ); 
          ceta(E<1e-2) = ;
          E(E<1e-2) = ;
          power_dB = 10.*log10(E.^2);
          power_dB = power_dB - max(power_dB);
          max(power_dB)
          polarplot(ceta,power_dB);
          rlim([-40 0]);


          Gives:



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 23:15









          MattMatt

          1,159112




          1,159112













          • i have a question, when 10*log10(E.^2) tends to large value i think rlim([ -40 0]) should remove it so why that is not happened?

            – user288086
            Nov 19 '18 at 23:31













          • rlim is only controlling the figure axis. What's happening is as you plot value larger than -40 (in terms of magnitude) its passing through the origin and continuing to the edges of the plot. Try this, remove the line I suggested and add in power_dB(power_dB < -60) = -60 right before your polar plot. You'll see the lines come back, but stop at 2 circles out from the center. This represents the -60 value once they've passed through the origin.

            – Matt
            Nov 19 '18 at 23:44













          • Also, looking at this a second time better solution might have been to just use power_dB(power_dB < -40) = -40, rather than my suggested change.

            – Matt
            Nov 19 '18 at 23:45











          • E = abs(cos(cos(ceta)*pi/2) ./ sin(ceta)); would suffice, cutting down on the LISP style usage of brackets.

            – Adriaan
            Nov 30 '18 at 22:21



















          • i have a question, when 10*log10(E.^2) tends to large value i think rlim([ -40 0]) should remove it so why that is not happened?

            – user288086
            Nov 19 '18 at 23:31













          • rlim is only controlling the figure axis. What's happening is as you plot value larger than -40 (in terms of magnitude) its passing through the origin and continuing to the edges of the plot. Try this, remove the line I suggested and add in power_dB(power_dB < -60) = -60 right before your polar plot. You'll see the lines come back, but stop at 2 circles out from the center. This represents the -60 value once they've passed through the origin.

            – Matt
            Nov 19 '18 at 23:44













          • Also, looking at this a second time better solution might have been to just use power_dB(power_dB < -40) = -40, rather than my suggested change.

            – Matt
            Nov 19 '18 at 23:45











          • E = abs(cos(cos(ceta)*pi/2) ./ sin(ceta)); would suffice, cutting down on the LISP style usage of brackets.

            – Adriaan
            Nov 30 '18 at 22:21

















          i have a question, when 10*log10(E.^2) tends to large value i think rlim([ -40 0]) should remove it so why that is not happened?

          – user288086
          Nov 19 '18 at 23:31







          i have a question, when 10*log10(E.^2) tends to large value i think rlim([ -40 0]) should remove it so why that is not happened?

          – user288086
          Nov 19 '18 at 23:31















          rlim is only controlling the figure axis. What's happening is as you plot value larger than -40 (in terms of magnitude) its passing through the origin and continuing to the edges of the plot. Try this, remove the line I suggested and add in power_dB(power_dB < -60) = -60 right before your polar plot. You'll see the lines come back, but stop at 2 circles out from the center. This represents the -60 value once they've passed through the origin.

          – Matt
          Nov 19 '18 at 23:44







          rlim is only controlling the figure axis. What's happening is as you plot value larger than -40 (in terms of magnitude) its passing through the origin and continuing to the edges of the plot. Try this, remove the line I suggested and add in power_dB(power_dB < -60) = -60 right before your polar plot. You'll see the lines come back, but stop at 2 circles out from the center. This represents the -60 value once they've passed through the origin.

          – Matt
          Nov 19 '18 at 23:44















          Also, looking at this a second time better solution might have been to just use power_dB(power_dB < -40) = -40, rather than my suggested change.

          – Matt
          Nov 19 '18 at 23:45





          Also, looking at this a second time better solution might have been to just use power_dB(power_dB < -40) = -40, rather than my suggested change.

          – Matt
          Nov 19 '18 at 23:45













          E = abs(cos(cos(ceta)*pi/2) ./ sin(ceta)); would suffice, cutting down on the LISP style usage of brackets.

          – Adriaan
          Nov 30 '18 at 22:21





          E = abs(cos(cos(ceta)*pi/2) ./ sin(ceta)); would suffice, cutting down on the LISP style usage of brackets.

          – Adriaan
          Nov 30 '18 at 22:21


















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383828%2fsomething-strange-using-polar-plot-function-in-matlab%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

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          SQL update select statement

          'app-layout' is not a known element: how to share Component with different Modules