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.

2 vues (au cours des 30 derniers jours)
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));

Réponse acceptée

Mathieu NOE
Mathieu NOE le 8 Déc 2020
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')

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by