Move/delete/create some coordinates in order to make the curve more or less uniform
1 view (last 30 days)
Show older comments
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).
I am trying to make the black curve more or less uniform with the coordinates marked by dots in red.
0 Comments
Answers (1)
Image Analyst
on 13 Dec 2022
Edited: Image Analyst
on 13 Dec 2022
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 Comments
Image Analyst
on 15 Dec 2022
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.
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!