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 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Wesley
am 7 Dez. 2020
Beantwortet: Mathieu NOE
am 8 Dez. 2020
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));
0 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 8 Dez. 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')
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Scatter Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!