logidx = abs(diff(Y)) < 0.022;
dY_idx = find([logidx 0] | [0 logidx]);
Y_adj_close = Y( dY_idx );
Seems to me that every part of these three lines is required, but maybe it can be made even faster.
Of course number of lines alone isn't the only thing to consider. I'd imagine this would be slower:
dY_idx = find([abs(diff(Y)) < 0.022 0] | [0 abs(diff(Y)) < 0.022]);
Y_adj_close = Y( dY_idx );
6 Comments
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_888296
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_888296
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_888302
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_888302
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_889331
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_889331
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_889340
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_889340
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_889523
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_889523
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_889526
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/543197-plot-only-adjacent-points-that-are-close-to-each-other#comment_889526
Sign in to comment.