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!

 채택된 답변

Joseph Cheng
Joseph Cheng 2014년 9월 4일

1 개 추천

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

Nik Sofoulis
Nik Sofoulis 2014년 9월 5일
Thank you Joseph for your answer!
I copy your code, but there exist some problems: a)The polar diagram that is produced when at the end of polar2 function i add clicktest() is not at dBs.Also it is different from the correct. I attach you one figure that is produced without clicktest, and the other one that is produced with clicktest.
b)The green cursor does not follow exactly the mouse pointer. Instead it traverse the red line, as the datacursor of matlab would do, when key arrows is pressed.
I am looking forward for your answer. Thank you again!
Nik Sofoulis
Nik Sofoulis 2014년 9월 5일
I am sorry! Now i am understanting the clicktest is an example and thats why thw plots are different. I will see it again!
Joseph Cheng
Joseph Cheng 2014년 9월 5일
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 2014년 9월 5일
편집: Nik Sofoulis 2014년 9월 5일
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!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Nik Sofoulis
Nik Sofoulis 2014년 9월 19일
편집: Nik Sofoulis 2014년 9월 19일

0 개 추천

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
%

카테고리

태그

질문:

2014년 9월 4일

편집:

2014년 9월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by