How do I extract data between a range in an XY array

I've been using MATLAB for a while but can't seem to find an efficient way of selecting XY data between a range.
I have a large physical data set imported which is an array of XY data points, I've tried to fake a section below:
dummyXYArray = [transpose([0:1:10]) rand(11,1)];
How do I return a similarly formed array with only data between 2<x_desired<7
My slow way requires tons of steps:
xDataDummyXYArray = dummyXYArray(:,1);
yDataDummyXYArray = dummyXYArray(:,2);
clippingArray = xDataDummyXYArray>2 & xDataDummyXYArray<7;
clippedArray = [xDataDummyXYArray(clippingArray) yDataDummyXYArray(clippingArray)]

 Accepted Answer

This would be my approach:
dummyXYArray = [transpose([0:1:10]) rand(11,1)];
clipped_array = dummyXYArray((dummyXYArray(:,1) > 2) & (dummyXYArray(:,1) < 7), :)

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!