Move/delete/create some coordinates in order to make the curve more or less uniform
1 次查看(过去 30 天)
显示 更早的评论
Hello! As written in the title I am trying to figure out if there is a way to move/delete/create some coordinates in order to make the curve more or less uniform.
Below is an example (whose coordinates can be found in the attached .txt. text file).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1229982/image.png)
I am trying to make the black curve more or less uniform with the coordinates marked by dots in red.
0 个评论
回答(1 个)
Image Analyst
2022-12-13
编辑:Image Analyst
2022-12-13
The attached file is a .mat file, not a txt file. The attached data is not sorted. Is there anyway you could sort it clockwise? I got this but it's not good because your data is not sorted. I wanted to see if you had sorted data before I tried to sort it better.
data = load('coordinate_A.mat')
x = data.out_both(:, 1);
y = data.out_both(:, 2);
% plot(x, y, 'c.', 'MarkerSize', 8)
hold on;
grid on;
axis equal
% The data is not sorted so we can't smooth it yet.
% Need to sort it clockwise.
% First need to find centroid
% Get left shape
leftIndexes = x < 250;
xLeft = x(leftIndexes);
yLeft = y(leftIndexes);
plot(xLeft, yLeft, 'b.');
hold on;
% Find centroid.
p = polyshape(xLeft, yLeft);
[xCentroid, yCentroid] = centroid(p)
plot(xCentroid, yCentroid, 'r+', 'MarkerSize', 40, 'LineWidth',2);
% Get angles
angles = atan2d(yLeft-yCentroid, xLeft-xCentroid);
% Sort
[sortedAngles, sortOrder] = sort(angles, 'ascend');
% Sort x and y the same way.
xLeft = xLeft(sortOrder);
yLeft = yLeft(sortOrder);
% Smooth both
windowWidth = 5;
xSmooth = movmean(xLeft, windowWidth);
ySmooth = movmean(yLeft, windowWidth);
plot(xSmooth, ySmooth, 'r-', 'LineWidth',2)
9 个评论
Image Analyst
2022-12-15
Since your data are integers, you could write them into an image and then use bwboundaries to get them in a sorted manner, then use movmean or sgloayfilt to smooth them. Try that.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!