Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Several polar plots on the same figure

Subject: Several polar plots on the same figure

From: kawak

Date: 14 Jul, 2010 16:40:23

Message: 1 of 7

Hello all,

I have got a simple question. I would like to plot three functions on the same polar plot.

Here my code:

clear all
% Define the wind load
W=1700; %N
y=1;

% Define the wind angle
for i=0:0.01:2*pi;

% Variation of the tension load in the fisrt cable
    T1(y)=W*cos(i);
    
    if T1(y)<0
        T1(y)=0;
    end
    
    % Variation of the tension load in the second cable
    T2(y)=W*cos(i+2*pi/3);
    
    if T2(y)<0
        T2(y)=0;
    end
% Variation of the tension load in the third cable
    T3(y)=W*cos(i+4*pi/3);
    
     if T3(y)<0
        T3(y)=0;
    end
    
    y=y+1;
end

i=0:0.01:2*pi;
hold on
polar(i,T1)
polar(i,T2)
polar(i,T3)
hold off


By using this code, at the end instead of having a polar angle plot, I've got a simple plot. Do you know how to plot these three functions (T1, T2 and T3) on the same polar plot?

Thank you

Benjamin

Subject: Several polar plots on the same figure

From: Raj Kamal

Date: 14 Jul, 2010 18:35:20

Message: 2 of 7

"kawak " <kbenjamin@hotmail.fr> wrote in message <i1kp9n$42q$1@fred.mathworks.com>...
> Hello all,
>
> I have got a simple question. I would like to plot three functions on the same polar plot.
>
> Here my code:
>
> clear all
> % Define the wind load
> W=1700; %N
> y=1;
>
> % Define the wind angle
> for i=0:0.01:2*pi;
>
> % Variation of the tension load in the fisrt cable
> T1(y)=W*cos(i);
>
> if T1(y)<0
> T1(y)=0;
> end
>
> % Variation of the tension load in the second cable
> T2(y)=W*cos(i+2*pi/3);
>
> if T2(y)<0
> T2(y)=0;
> end
> % Variation of the tension load in the third cable
> T3(y)=W*cos(i+4*pi/3);
>
> if T3(y)<0
> T3(y)=0;
> end
>
> y=y+1;
> end
>
> i=0:0.01:2*pi;
> hold on
> polar(i,T1)
> polar(i,T2)
> polar(i,T3)
> hold off
>
>
> By using this code, at the end instead of having a polar angle plot, I've got a simple plot. Do you know how to plot these three functions (T1, T2 and T3) on the same polar plot?
>
> Thank you
>
> Benjamin


Use curve fitting tool cftool...first make your data thn use this cftool.

Subject: Several polar plots on the same figure

From: someone

Date: 14 Jul, 2010 19:08:04

Message: 3 of 7

"kawak " <kbenjamin@hotmail.fr> wrote in message <i1kp9n$42q$1@fred.mathworks.com>...
> Hello all,
>
> I have got a simple question. I would like to plot three functions on the same polar plot.
>
> Here my code:
>
> clear all
> % Define the wind load
> W=1700; %N
> y=1;
>
> % Define the wind angle
> for i=0:0.01:2*pi;
>
> % Variation of the tension load in the fisrt cable
> T1(y)=W*cos(i);
>
> if T1(y)<0
> T1(y)=0;
> end
>
> % Variation of the tension load in the second cable
> T2(y)=W*cos(i+2*pi/3);
>
> if T2(y)<0
> T2(y)=0;
> end
> % Variation of the tension load in the third cable
> T3(y)=W*cos(i+4*pi/3);
>
> if T3(y)<0
> T3(y)=0;
> end
>
> y=y+1;
> end
>
> i=0:0.01:2*pi;
> hold on
> polar(i,T1)
> polar(i,T2)
> polar(i,T3)
> hold off
>
>
> By using this code, at the end instead of having a polar angle plot, I've got a simple plot. Do you know how to plot these three functions (T1, T2 and T3) on the same polar plot?
>
> Thank you
>
> Benjamin

% You're close. Simply change:
i=0:0.01:2*pi;
hold on
polar(i,T1)
polar(i,T2)
polar(i,T3)
hold off

% to:
i=0:0.01:2*pi;
polar(i,T1)
hold on
polar(i,T2)
polar(i,T3)
hold off

% in the above code.
% Your code can be optimized quite a bit.
% But thats another story. It works for me.

Subject: Several polar plots on the same figure

From: kawak

Date: 14 Jul, 2010 19:44:04

Message: 4 of 7

"someone" <someone@somewhere.net> wrote in message <i1l1uk$3k9$1@fred.mathworks.com>...
> "kawak " <kbenjamin@hotmail.fr> wrote in message <i1kp9n$42q$1@fred.mathworks.com>...
> > Hello all,
> >
> > I have got a simple question. I would like to plot three functions on the same polar plot.
> >
> > Here my code:
> >
> > clear all
> > % Define the wind load
> > W=1700; %N
> > y=1;
> >
> > % Define the wind angle
> > for i=0:0.01:2*pi;
> >
> > % Variation of the tension load in the fisrt cable
> > T1(y)=W*cos(i);
> >
> > if T1(y)<0
> > T1(y)=0;
> > end
> >
> > % Variation of the tension load in the second cable
> > T2(y)=W*cos(i+2*pi/3);
> >
> > if T2(y)<0
> > T2(y)=0;
> > end
> > % Variation of the tension load in the third cable
> > T3(y)=W*cos(i+4*pi/3);
> >
> > if T3(y)<0
> > T3(y)=0;
> > end
> >
> > y=y+1;
> > end
> >
> > i=0:0.01:2*pi;
> > hold on
> > polar(i,T1)
> > polar(i,T2)
> > polar(i,T3)
> > hold off
> >
> >
> > By using this code, at the end instead of having a polar angle plot, I've got a simple plot. Do you know how to plot these three functions (T1, T2 and T3) on the same polar plot?
> >
> > Thank you
> >
> > Benjamin
>
> % You're close. Simply change:
> i=0:0.01:2*pi;
> hold on
> polar(i,T1)
> polar(i,T2)
> polar(i,T3)
> hold off
>
> % to:
> i=0:0.01:2*pi;
> polar(i,T1)
> hold on
> polar(i,T2)
> polar(i,T3)
> hold off
>
> % in the above code.
> % Your code can be optimized quite a bit.
> % But thats another story. It works for me.

Thank you very much both of you for your answer.

I don't how I can improve this code. At least I need one for loop and three if loops no?

Thank you

Benjamin

Subject: Several polar plots on the same figure

From: someone

Date: 14 Jul, 2010 20:12:05

Message: 5 of 7

"kawak " <kbenjamin@hotmail.fr> wrote in message <i1l424$mel$1@fred.mathworks.com>...
> "someone" <someone@somewhere.net> wrote in message <i1l1uk$3k9$1@fred.mathworks.com>...
> > "kawak " <kbenjamin@hotmail.fr> wrote in message <i1kp9n$42q$1@fred.mathworks.com>...
> > > Hello all,
> > >
> > > I have got a simple question. I would like to plot three functions on the same polar plot.
> > >
> > > Here my code:
> > >
> > > clear all
> > > % Define the wind load
> > > W=1700; %N
> > > y=1;
> > >
> > > % Define the wind angle
> > > for i=0:0.01:2*pi;
> > >
> > > % Variation of the tension load in the fisrt cable
> > > T1(y)=W*cos(i);
> > >
> > > if T1(y)<0
> > > T1(y)=0;
> > > end
> > >
> > > % Variation of the tension load in the second cable
> > > T2(y)=W*cos(i+2*pi/3);
> > >
> > > if T2(y)<0
> > > T2(y)=0;
> > > end
> > > % Variation of the tension load in the third cable
> > > T3(y)=W*cos(i+4*pi/3);
> > >
> > > if T3(y)<0
> > > T3(y)=0;
> > > end
> > >
> > > y=y+1;
> > > end
> > >
> > > i=0:0.01:2*pi;
> > > hold on
> > > polar(i,T1)
> > > polar(i,T2)
> > > polar(i,T3)
> > > hold off
> > >
> > >
> > > By using this code, at the end instead of having a polar angle plot, I've got a simple plot. Do you know how to plot these three functions (T1, T2 and T3) on the same polar plot?
> > >
> > > Thank you
> > >
> > > Benjamin
> >
> > % You're close. Simply change:
> > i=0:0.01:2*pi;
> > hold on
> > polar(i,T1)
> > polar(i,T2)
> > polar(i,T3)
> > hold off
> >
> > % to:
> > i=0:0.01:2*pi;
> > polar(i,T1)
> > hold on
> > polar(i,T2)
> > polar(i,T3)
> > hold off
> >
> > % in the above code.
> > % Your code can be optimized quite a bit.
> > % But thats another story. It works for me.
>
> Thank you very much both of you for your answer.
>
> I don't how I can improve this code. At least I need one for loop and three if loops no?
>
> Thank you
>
> Benjamin

% You don't need any for loops or if conditions.
% Consider the following:

clear all;
W = 1700;
ii = 0:0.01:2*pi;
T1 = W*cos(ii);
T1 = max(0,T1);
polar(ii,T1)
hold on

% I'll leave T2 & T3 to you.

% PS Try to avoid using i or j for indexes
% By default, they are sqrt(-1).
% You can override them as you did,
 % but sooner or later this will bite you.

Subject: Several polar plots on the same figure

From: kawak

Date: 14 Jul, 2010 21:02:08

Message: 6 of 7

"someone" <someone@somewhere.net> wrote in message <i1l5ml$c58$1@fred.mathworks.com>...
> "kawak " <kbenjamin@hotmail.fr> wrote in message <i1l424$mel$1@fred.mathworks.com>...
> > "someone" <someone@somewhere.net> wrote in message <i1l1uk$3k9$1@fred.mathworks.com>...
> > > "kawak " <kbenjamin@hotmail.fr> wrote in message <i1kp9n$42q$1@fred.mathworks.com>...
> > > > Hello all,
> > > >
> > > > I have got a simple question. I would like to plot three functions on the same polar plot.
> > > >
> > > > Here my code:
> > > >
> > > > clear all
> > > > % Define the wind load
> > > > W=1700; %N
> > > > y=1;
> > > >
> > > > % Define the wind angle
> > > > for i=0:0.01:2*pi;
> > > >
> > > > % Variation of the tension load in the fisrt cable
> > > > T1(y)=W*cos(i);
> > > >
> > > > if T1(y)<0
> > > > T1(y)=0;
> > > > end
> > > >
> > > > % Variation of the tension load in the second cable
> > > > T2(y)=W*cos(i+2*pi/3);
> > > >
> > > > if T2(y)<0
> > > > T2(y)=0;
> > > > end
> > > > % Variation of the tension load in the third cable
> > > > T3(y)=W*cos(i+4*pi/3);
> > > >
> > > > if T3(y)<0
> > > > T3(y)=0;
> > > > end
> > > >
> > > > y=y+1;
> > > > end
> > > >
> > > > i=0:0.01:2*pi;
> > > > hold on
> > > > polar(i,T1)
> > > > polar(i,T2)
> > > > polar(i,T3)
> > > > hold off
> > > >
> > > >
> > > > By using this code, at the end instead of having a polar angle plot, I've got a simple plot. Do you know how to plot these three functions (T1, T2 and T3) on the same polar plot?
> > > >
> > > > Thank you
> > > >
> > > > Benjamin
> > >
> > > % You're close. Simply change:
> > > i=0:0.01:2*pi;
> > > hold on
> > > polar(i,T1)
> > > polar(i,T2)
> > > polar(i,T3)
> > > hold off
> > >
> > > % to:
> > > i=0:0.01:2*pi;
> > > polar(i,T1)
> > > hold on
> > > polar(i,T2)
> > > polar(i,T3)
> > > hold off
> > >
> > > % in the above code.
> > > % Your code can be optimized quite a bit.
> > > % But thats another story. It works for me.
> >
> > Thank you very much both of you for your answer.
> >
> > I don't how I can improve this code. At least I need one for loop and three if loops no?
> >
> > Thank you
> >
> > Benjamin
>
> % You don't need any for loops or if conditions.
> % Consider the following:
>
> clear all;
> W = 1700;
> ii = 0:0.01:2*pi;
> T1 = W*cos(ii);
> T1 = max(0,T1);
> polar(ii,T1)
> hold on
>
> % I'll leave T2 & T3 to you.
>
> % PS Try to avoid using i or j for indexes
> % By default, they are sqrt(-1).
> % You can override them as you did,
> % but sooner or later this will bite you.

Wouaa I am really impressed. I didn't know this tricky thing with the max function.I thought that the max function is used only to return the maximum value of the list. Thank you very much.

Last question I promise, do you know how to change the LineWidth and to put color inside the circle with the polar function? I know I can do it with
A=polar(ii,T1)
set(A,'LineWidth',2,'MarkerFaceColor','k')

These functions work with plot but it seems that it doesn't work with the polar plot

Once again thank you

Benjamin

Subject: Several polar plots on the same figure

From: someone

Date: 14 Jul, 2010 23:36:04

Message: 7 of 7

"kawak " <kbenjamin@hotmail.fr> wrote in message <i1l8kg$q1r$1@fred.mathworks.com>...
snip ...
>
> Last question I promise, do you know how to change the LineWidth and to put color inside the circle with the polar function? I know I can do it with
> A=polar(ii,T1)
> set(A,'LineWidth',2,'MarkerFaceColor','k')
>
> These functions work with plot but it seems that it doesn't work with the polar plot
>
> Once again thank you
>
> Benjamin

The above commands work, but maybe not the way you think they should.

doc LineSpec

The LineWidth property should work OK.
But the MarkerFaceColor won't fill in the circle you plotted.
It fills in markers "on the line" you are not using.

To see them try:
set(A,'LineWidth',2,'Marker','o','MarkerFaceColor','k')

To do what you want may not be possible
(at least not easily).

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us