Hello everyone, I now have a set of data. I would like to ask how to draw these scattered points in polar coordinates with the centroid point as the center.

조회 수: 4 (최근 30일)
It is difficult to draw a closed polar coordinate curve.
load data1.mat
x=data1(:,1);y=data1(:,2);
hold on
plot(centroids(:,1),centroids(:,2),'b*')
[x y]=data1;
[theta,r] = cart2pol(x,y);
% closing the circle
r(end+1) = r(1);
theta(end+1) = theta(1);
% convert to cartesian
[x,y] = pol2cart(theta,r);
% interpolate with parameter t
t = (1:n)';
v = [x,y];
tt = linspace(1,n,100);
X = interp1(t,v,tt,'pchip');
% plot
plot(x,y,'o');
hold on
plot(X(:,1),X(:,2));

채택된 답변

Mathieu NOE
Mathieu NOE 2020년 12월 8일
hello
this would be my suggestion :
load data1.mat
load centroids.mat
x=data1(:,1)-centroids(:,1); % centered plot
y=data1(:,2)-centroids(:,2); % centered plot
[theta,r] = cart2pol(x,y);
% closing the circle
r(end+1) = r(1);
theta(end+1) = theta(1);
% sort theta in ascending order
[theta_sorted,ind] = sort(theta);
r_sorted = r(ind);
% remove duplicates before interpolation
[theta_unique,IA,IC] = unique(theta_sorted);
r_unique = r_sorted(IA);
% interpolation on n values to make it nicer
n = 360; % 1 deg resolution
theta_n = linspace(min(theta_unique),max(theta_unique),n);
r_n = interp1(theta_unique,r_unique,theta_n);
% convert to cartesian
[xn,yn] = pol2cart(theta_n,r_n);
%% XY plot
figure(1),plot(x,y,'b.',xn,yn,'o');grid
%% polar plot
figure(2),polarplot(theta_n, r_n,'--r')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by