Polar Plot with a moving marker

14 views (last 30 days)
Hi to everyone
I am trying to plot Array Factor of an antenna using Polar2 function. I would like to know if there is any way to have a moving marker above the plot which it will follow the cursor of mouse. More specific i want to show the dBs of Array Factor as regards to angle. I want to draw a marker, which will be like a radius, and will be moving arround the circle (as regards to mouse) of polar plot and in a given angle it will show the dBs. It follows an image of a polar plot and the marker is with purple.
Thank you in advance!

Accepted Answer

Joseph Cheng
Joseph Cheng on 4 Sep 2014
Not entirely sure what you mean by move around the circle but here is an example:
function clicktest()
theta = 0:0.01:2*pi;
rho = sin(2*theta).*cos(2*theta);
figure
ax(1) = polar(theta,rho,'--r');
hold on
ax(2) = polar(NaN,NaN,'g*');
set (gcf, 'WindowButtonMotionFcn', {@mouseMove,ax});
function mouseMove(object, eventdata,ax)
C = get (gca, 'CurrentPoint');
[theta rho] = cart2pol(C(1,1), C(1,2));
title(gca, ['(angle,factor) = (', num2str(theta*180/pi), ', ',num2str(rho), ')']);
markerspot = sin(2*theta).*cos(2*theta);
[x y]=pol2cart(theta,markerspot);
set(ax(2),'xData',x,'yData',y,'markersize',20);
  4 Comments
Joseph Cheng
Joseph Cheng on 5 Sep 2014
oh if you want to track the mouse then instead of calculating the marker spot just substitute the x and y data for C(1,1) and C(1,2). the return for mouse position is stored in C.
Nik Sofoulis
Nik Sofoulis on 5 Sep 2014
Edited: Nik Sofoulis on 5 Sep 2014
Hi again
I try to fit your code to my problem. I haven't done much. I succeed in plot my array factor, but i have two problems. The first is that the displayed radius doesn't follow the exact radius of plot. More specific the displayed radius is increasing as the mouse travels from the center to the external place of circle. Instead dBs is decreasing (in absolute value) as we travel from the center to external place. The second problem is that i can't make the green marker to move. Here is my code:
function clicktest(AF1)
theta = 0:0.0175:2*pi;
rho = AF1;
figure
ax(1) = polar2(theta,rho,[-50 0],'r');
hold on
ax(2) = polar2(NaN,NaN,[-50 0],'g*');
set (gcf, 'WindowButtonMotionFcn', {@mouseMove,ax});
function mouseMove(object, eventdata,ax)
C = get (gca, 'CurrentPoint');
[theta rho] = cart2pol(C(1,1),(C(1,2)));
title(gca, ['(angle,factor) = (', num2str(theta*180/pi), ', ',num2str(rho), ')']);
%markerspot = sin(2*theta).*cos(2*theta);
AF_test=cheb_x_dip_y('nr',0,1.5708,3.1416,2,[0.8182 1],1.5708,3,pi/2,theta);
AF_test_m=max(AF_test);
markerspot=20.*log10(abs(AF_test./AF_test_m));
[x y]=pol2cart(theta,markerspot);
set(ax(2),'xData',x,'yData',y,'markersize',20);
I attach you a figure to see how is the plot that i have drawn, with your help:
I am looking forward for your answer. Thanks again!

Sign in to comment.

More Answers (1)

Nik Sofoulis
Nik Sofoulis on 19 Sep 2014
Edited: Nik Sofoulis on 19 Sep 2014
Hi mates again. After the significant help of Joseph and some experimentation of mine, i finally came to the code that follows. To explain again i needed a moving marker in the form of a straight line tha would follow mouse pointer and would give the values of angle and array factor. Code:
function clicktest_6()
theta = 0:0.0175:2*pi;
AF1= abs(sin(2*theta).*cos(2*theta));
figure
ax(1) = polar(theta,AF1,'r');
hold on
ax(2) = polar([0 0],[0 0.5],'g');
set (gcf, 'WindowButtonMotionFcn', {@mouseMove,ax,AF1});
function mouseMove(object, eventdata,ax,AF1)
C = get (gca, 'CurrentPoint');
[theta rho] = cart2pol(C(1,1), C(1,2));
if theta<0
theta=2*pi+theta;
end
theta_f=round(rad2deg(theta));
if theta_f==0
theta_f=1;
end
AF_text=AF1(theta_f);
title(gca, ['(angle,factor) = (', num2str(theta_f), ', ',num2str(AF_text), ')']);
theta_m=[0 theta];
r_m=[0 0.5];
[x y]=pol2cart(theta_m,r_m);
set(ax(2),'xData',x,'yData',y);
one picture that corresponds to this code,follows
%

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!