Colouring/shading of a sector of a polar representation in combination with animatedline
조회 수: 2 (최근 30일)
이전 댓글 표시
How do I combine the animation of an animatedline with a 30° sector? I would like the animated point of the animatedline to always be highlighted with a 30° sector (+-15°). The animated line should become longer and longer, while the sector runs along with the first point and disappears as soon as the 360° is reached. I have the following code for the animated line and for the 30° sector, but I have no idea how to combine them as described.
%polarplot
ax = polaraxes('ThetaZeroLocation', 'top');
polarplot(ax, 0, 1);
hold on;
random_vector = 10 + (20 - 10) * rand(1, 360);
theta_rad = deg2rad(1:360);
rlim([0, max(random_vector)]);
h = animatedline(ax, 'Color', 'b', 'LineWidth', 2);
for i = 1:length(random_vector)
addpoints(h, theta_rad(i), random_vector(i));
drawnow;
pause(0.01);
end
hold off;
%highlighted sektor
teta= linspace(0,pi/6,500);
rho = [0 100*ones(499,1)'];
a = polar(teta,rho);
patch( get(a,'XData'), get(a,'YData'),[0, 0.4470, 0.7410],'FaceAlpha',0.2);
댓글 수: 0
채택된 답변
Ganesh
2024년 6월 12일
Starting R2024a, you can achieve this using "polarregion()". You can use "theta_rad(i)" to find the range of theta and plot accordingly. You can use the code below:
%polarplot
ax = polaraxes('ThetaZeroLocation', 'top');
hold on;
random_vector = 10 + (20 - 10) * rand(1, 360);
theta_rad = deg2rad(1:360);
rlim([0, max(random_vector)]);
h = animatedline(ax, 'Color', 'b', 'LineWidth', 2);
% Initial sector plot (invisible at start)
sectorAngle = 15;
sectorPlot = polarplot(ax, [0, 0], [0, 0], 'r', 'LineWidth', 2);
teta1 = 0;
rho1 = 1;
teta2 = pi/6;
rho2 = 1;
prev = polarregion([0 pi/6], [0 max(random_vector)]);
for i = 1:length(random_vector)
addpoints(h, theta_rad(i), random_vector(i));
drawnow;
pause(0.01);
sectorStart = theta_rad(i) - deg2rad(sectorAngle);
sectorEnd = theta_rad(i) + deg2rad(sectorAngle);
prev.FaceAlpha = 0;
prev = polarregion([sectorStart sectorEnd], [0 max(random_vector)]);
end
prev.FaceAlpha = 0;
hold off;
Please find the relevant documentation on "polarregion" below:
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Polar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!