How to select multiple sets of data points from a scatter plot (like gating in flow cytometry/cell sorting)?
7 views (last 30 days)
I have 2 of column vectors that I plotted on a scatter plot. This is cell sorting data. I gated the data using reference lines (see png) I want to be able to export (x,y) data points between the specific lines. Is this possible? I'm using R2019b.
Adam Danz on 28 Sep 2021
Edited: Adam Danz on 30 Sep 2021
Using the slope and y-intercept of each reference line, determine which points contain y-values less than the upper line and which points contain y-values greater than the lower line.
Create demo data. I assume you've computed the log() for each x and y since the axis scales are not log.
x = exp(linspace(2.2,5.8,500));
y = exp(log(x)+rand(size(x)).*linspace(2,.1,numel(x))-1);
% Define slope and y-intercepts for each line
slope = 0.74484;
yint = -1:.5:2;
% Convert x,y to log
xlog = log(x);
ylog = log(y);
h = plot(xlog, ylog, 'o');
Add reference lines. I assume you already have the slope and y-intercept info.
% Label lines
text(6*ones(size(yint)), slope*6+yint, compose('%d',1:numel(yint)))
Isolate dots between two reference lines. For this demo, we're isolating dots between the 3rd and 5th lines.
% isolate dots between lines 3 and 5
isBetween = ylog > slope*xlog+yint(3) & ylog < slope*xlog+yint(5);
% ^ ^
Plot the isolated points and return their x,y values
% Label selected dots
xBetween = xlog(isBetween);
yBetween = ylog(isBetween);
h2 = plot(xBetween, yBetween, 'r.');
legend([h,h2], 'All data', 'Data between lines 3 and 5')