I have a 3 column matrix, xyK, that contains x and y coordinates and the value of curvature at each of those coordinates. I'm trying to find the peak values of curvature and the coordinates they occur at and put that information into another 3 column matrix. findpeaks(xyK(:,3)) is returning the peak values of curvature as I need but when I tried to use [pks,locs] to find the corresponding (x,y) coordinates it's returning the distance along the curve and not the coordinates of the point the curvature occurs at. I suspect this is because the curvature is plotted against length but I have a matrix with all the corresponding values so I feel like there must be a simpler way to just lift out the rows that have a peak value in the third column? function [L,R,C,xyK] = curvature(xy) % Radius of curvature and curvature vector for 2D or 3D curve % [L,R,C] = curvature(X) % X: 2 or 3 column array of x, y (and possibly z) coordiates % L: Cumulative arc length % R: Radius of curvature % C: Curvature vector N = size(xy,1); dims = size(xy,2); if dims == 2 xy = [xy,zeros(N,1)]; % Do all calculations in 3D end L = zeros(N,1); R = NaN(N,1); C = NaN(N,3); xyK = zeros(N,3); for i = 2:N-1 [R(i),~,C(i,:)] = circumcenter(xy(i,:)',xy(i-1,:)',xy(i+1,:)'); L(i) = L(i-1)+norm(xy(i,:)-xy(i-1,:)); end i = N; L(i) = L(i-1)+norm(xy(i,:)-xy(i-1,:)); if dims == 2 C = C(:,1:2); end xyK = [xy(:,1:2), C(:,2)];
Prashant Kumar answered .
2025-11-20
Try This:
[~,locs] = findpeaks(xyK(:,3)); sol = xyK(locs,:);