How to select multiple sets of data points from a scatter plot (like gating in flow cytometry/cell sorting)?
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Adam Danz
2021-9-28
编辑:Adam Danz
2021-9-30
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);
Plot results
h = plot(xlog, ylog, 'o');
xlim([2,6])
ylim([.5,7.7])
Add reference lines. I assume you already have the slope and y-intercept info.
arrayfun(@(y)refline(slope,y), yint)
% 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
hold on
xBetween = xlog(isBetween);
yBetween = ylog(isBetween);
h2 = plot(xBetween, yBetween, 'r.');
legend([h,h2], 'All data', 'Data between lines 3 and 5')
2 个评论
Adam Danz
2021-9-30
It looks like your reference lines are parallel and therefore share the same slope. If that's the case, they only vary by y-intercept. I've defined a single slope and 7 y-intercepts (see variables slope and yint). The y-intercepts are sorted in ascending order so the bottom line is line #1 and the top line is line #7.
In the section "Isolate dots between two reference lines", I've selected lines 3 and 5.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!