How to plot specified data points on a polar plot with curved lines, instead of straight lines
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I am trying to make a polar plot with the following code + data:
c_2 = [780.980150003248 900.818303825083 956.494860478838 855.216748671708 999.328305026861 784.311636929536 806.164595552563]
c_3 = [801.453331427611 896.652257229697 956.494860478838 855.216748671708 985.564716214628 806.880414115856 773.055886925425]
theta = [0 45 63.43494882 90 116.5650512 135.0000394 180];
theta_2 = [180 225 243.43494882 270 296.5650512 315.0000394 360];
polarplot (theta * (pi/180), c_2, '-b', 'Marker','o')
hold on
polarplot (theta_2 * (pi/180), c_3, '-r', 'Marker','x')
What I want is for the connections between the points to be curved, and not straight lines. Any suggestions?
댓글 수: 2
Dyuman Joshi
2023년 11월 23일
What should the be the nature of the curve?
Polynomial? Circular? or something else?
답변 (2개)
Chunru
2023년 11월 23일
c_2 = [780.980150003248 900.818303825083 956.494860478838 855.216748671708 999.328305026861 784.311636929536 806.164595552563]
c_3 = [801.453331427611 896.652257229697 956.494860478838 855.216748671708 985.564716214628 806.880414115856 773.055886925425]
theta = [0 45 63.43494882 90 116.5650512 135.0000394 180];
theta_2 = [180 225 243.43494882 270 296.5650512 315.0000394 360];
% try interpolation
theta_i = linspace(theta(1), theta(end), 101);
c_2i = interp1(theta, c_2, theta_i);
polarplot (theta * (pi/180), c_2, '-b', 'Marker','o')
hold on
polarplot (theta_i * (pi/180), c_2i, 'k-')
% Do the same for other half
polarplot (theta_2 * (pi/180), c_3, '-r', 'Marker','x')
댓글 수: 2
Chunru
2023년 11월 24일
Generate 101 points between the min and max theta. doc linspace for details.
You can try different interpolation methods. doc interp1.
Anyway, if you have two few points and you have to rely on the interpolation methods to guess the points in between and you may not have full control of the curve shape.
c_2 = [780.980150003248 900.818303825083 956.494860478838 855.216748671708 999.328305026861 784.311636929536 806.164595552563];
c_3 = [801.453331427611 896.652257229697 956.494860478838 855.216748671708 985.564716214628 806.880414115856 773.055886925425];
theta = [0 45 63.43494882 90 116.5650512 135.0000394 180];
theta_2 = [180 225 243.43494882 270 296.5650512 315.0000394 360];
% try interpolation
theta_i = linspace(theta(1), theta(end), 101);
c_2i = interp1(theta, c_2, theta_i, 'makima');
polarplot (theta * (pi/180), c_2, '-b', 'Marker','o')
hold on
polarplot (theta_i * (pi/180), c_2i, 'k-')
% Do the same for other half
polarplot (theta_2 * (pi/180), c_3, '-r', 'Marker','x')
Star Strider
2023년 11월 24일
I am not certain what result you want. The plot image you posted looks like a sort of spline fit, however when I tried a spline fit, it definitely did not look like the plot image. The only options seem to be the 'pchip' or 'makima' methods.
Try these —
c_2 = [780.980150003248 900.818303825083 956.494860478838 855.216748671708 999.328305026861 784.311636929536 806.164595552563];
c_3 = [801.453331427611 896.652257229697 956.494860478838 855.216748671708 985.564716214628 806.880414115856 773.055886925425];
theta = [0 45 63.43494882 90 116.5650512 135.0000394 180];
theta_2 = [180 225 243.43494882 270 296.5650512 315.0000394 360];
thetai = linspace(theta(1), theta(end));
theta_2i = linspace(theta_2(1), theta_2(end));
c_2i = interp1(theta, c_2, thetai, 'pchip');
c_3i = interp1(theta_2, c_3, theta_2i, 'pchip');
figure
polarplot (deg2rad(theta), c_2, '-b', 'Marker','o', 'DisplayName','c\_2')
hold on
polarplot (deg2rad(thetai), c_2i, '--b', 'DisplayName','Interpolation ‘pchip’: c\_2')
polarplot (deg2rad(theta_2), c_3, '-r', 'Marker','x', 'DisplayName','c\_3')
polarplot(deg2rad(theta_2i), c_3i, '--r', 'DisplayName','Interpolation ‘pchip’: c\_3')
hold off
legend('Location','bestoutside')
c_2i = interp1(theta, c_2, thetai, 'makima');
c_3i = interp1(theta_2, c_3, theta_2i, 'makima');
figure
polarplot (deg2rad(theta), c_2, '-b', 'Marker','o', 'DisplayName','c\_2')
hold on
polarplot (deg2rad(thetai), c_2i, '--b', 'DisplayName','Interpolation ‘makima’: c\_2')
polarplot (deg2rad(theta_2), c_3, '-r', 'Marker','x', 'DisplayName','c\_3')
polarplot(deg2rad(theta_2i), c_3i, '--r', 'DisplayName','Interpolation ‘makima’: c\_3')
hold off
legend('Location','bestoutside')
.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Curve Fitting Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!