Extract row from table immediately before/after specified range
Afficher commentaires plus anciens
Hello,
I am currently trying to code for preferential behavior for phototaxis in fly models. My idea is to focus on the "transition" between light and dark and the time spent there.
I am trying to extract data from a table that is immediately before and after a specified range to sort. In essence, I specify a filter for certain values where (x>y) in a predefined table. Could I grab the value immediately before first instance of that, and the one after?
So in table
1 2 3 4
5 6 7 8
9 10 11 12
13……….16
I grab data in cells 5-8 but is there a way to then also grab 9-12 and 1-4?
Currently, code below takes all instances where my yroi is greater or less than roicenter, plotting in different colors. However, I am more interested on the "transition period" which includes the data immediately before and immediately after that filter. So I am looking for a way to get the row of data immediately before and after y_roi > or < roicenter, so I can then find the difference between the two for all instances in my loop, before plotting it. So if fly wtransitions dark->light @ frame 200, but goes light->dark at frame 250, I am interested in the difference 250-200
End goal is to then plot this "preference score" in stacked bars as a percentage of total time.
Thanks in advance for the help.
%Calculate the center of each ROI
roicenter = expmt.meta.roi.centers(:,2);
%Set the days to analyze
start_time = seven_am_idx;
final_time = seven_am_idx + (259022);
%Extract Y values from Margo for ROI and setting comparisons
y_roi = squeeze(centroids(:,2,:));
asabove = (y_roi > roicenter');
sobelow = (y_roi < roicenter');
%Set up ROIs of interest
start_ROI = 1;
stop_ROI = 1;
bin = 240;
%--------------------------------------------------------------------------
%Set up a quick comparison to determine Preference Score for above the
%center
for j = (start_ROI:stop_ROI)
dummyabove = [];
dummybelow = [];
for i = (start_time:bin:final_time)
%all nonzero insances
abovetest = nonzeros(asabove(i:(i+bin),j));
abovetest = abovetest(~isnan(abovetest));
dummyabove(length(dummyabove)+1) = sum(abovetest);
%Set up a quick comparison to determine Preference Score for Below the
%center
belowtest = nonzeros(sobelow(i:(i+bin),j));
belowtest = belowtest(~isnan(belowtest));
dummybelow(length(dummybelow)+1) = sum(belowtest);
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Animation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!