How to use ginput to select points from existing plot
27 次查看(过去 30 天)
显示 更早的评论
I need to use 'ginput' to select points from a plot to receive x and y values. I am analyzing heel strike data when walking. I used 'islocalmin' to identify heel strikes, but it is identifying some points that are not heel strikes. These cannot be filtered out using something like 'isoutliar' because the values are too close to the heel strike points. It would be easiest to manually select the points using 'ginput' BUT when doing so the crosshairs appear and you are no longer in 'datacursormode'. I need the specific points from the graph as the x values are whole numbers that will correspond to a frame index that will be used in other calculations.
Here is the code for one of the plots. This is for the left heel. I just want to be able to select the local minimums I want to keep, and be able to select the EXACT data point. Not just the crosshairs
% HEEL STRIKE SELECT LHEE DATA WHOLE TRIAL
figure
hold on
plot(frame, LHEE_filtered(:,3))
plot(frame(heel_strikes_LHEE_index), LHEE_filtered(heel_strikes_LHEE_index,3),'*');
% LABELS
xlabel('Frame #')
ylabel('Z-axis (mm)')
title('SELECT HEEL STRIKE MARKERS FOR LHEE DATA')
legend('Left Heel', 'Local Minimums')
datacursormode('on')
[frame_LHEE_strikes, LHEE_strikes_z] = ginput;
0 个评论
回答(1 个)
Niranjan Sundararajan
2023-7-12
You can try smoothing the plot using maybe gaussian smoothing and then use the smoothed values to determine the local minimums. That would cause only heel strikes to appear. Alternatively, you could parse the mouse input pixel from the graph (see documentation for ginput) and search the closest heel strike point to it in another MATLAB script.
clicked_point = ginput(1);
closest_point = [NaN, NaN];
minDist = Inf;
for idx = 1:length(heel_strike_points)
if dist(clicked_point, heel_strike_point(idx)) < minDist
minDist = dist(clicked_point, heel_strike_point(idx));
closest_point = clicked_point;
end
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!