How do I group data into different groups based on values of 2 columns for analysis?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am biology student and do not have much experience with matlab programming other than simple codes for plotting graphs. I have tracked some living cells using a tracking software and the results are in csv format with location of a living cells (x and y positions) and their speed (attached is the sample dataset). I want to group all those cells within the same neighbourhood (for example within 3 µm difference in x and y position) and average their speed. How do I write the code to allocate them to different bins based on their min and max position and get their average speed? As long as x and y fall within a particular range , I want allocate them to a grid or bin to get their speed. I am not sure of the exact terminolgy here but hope I am able to convey my question clearly. I am new to this platform so appreciate any help. Thanks.
0 commentaires
Réponse acceptée
dpb
le 19 Avr 2023
Modifié(e) : dpb
le 19 Avr 2023
fn='https://www.mathworks.com/matlabcentral/answers/uploaded_files/1361218/position_velocity%20data.xlsx';
tLC=readtable(fn);
height(tLC)
head(tLC)
tLC.Properties.VariableNames={'X','Y','V'}; % let's set easier names to use...
histogram2(tLC.X,tLC.Y) % then just look at the dispersion
xlabel('X'),ylabel('Y')
That doesn't look too bad; you may want to try different numbers of bins in each direction just to see, probably would make sense to use equal distances in each direction, however, but we'll not get that sophisticated here... :) To count and get bin numbers, etc., isn't too tough, either...
[N,~,~,bX,bY]=histcounts2(tLC.X,tLC.Y); % count, keep bin IDs
tLC=addvars(tLC,bX,bY,'NewVariableNames',{'binX','binY'},'After','V'); % add the grouping variables
groupsummary(tLC,{'binX','binY'},{'mean'},{'X','Y','V'}) % find mean of position, speed
We didn't look at the counts before; this illustrates issues of not having scads of data when start splitting it up by multiple variables; there are quite a number of cells with only one or two counts; you may need to do some variably-spaced intervals to balance out the counts some; it's hard to put much of a bound on estimates with that few members in those bins.
I would guess one thing missing here, maybe. is the starting location of each so isn't just where they ended up but how far and in what net direction did each end up? In that case, you'd be grouping by individual if you had such information available.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!