MATLAB: Hi, I need help in writing a code formula

differential counts

I'm writing a series of code which count total of activations, how long activated and time to next activation. I have so far managed the Start points and end points but i'm not sure how to go about get time between the points and time to start of next activation in time increments.
ATsyt2= T.ATSys.signals.values==2; % Channel
FATsyt2=find(ATsyt2==1); % Determine when condition is met
starATsyt2=FATsyt2([0; diff(FATsyt2)]>1); %Start of Activation
endFATsyt2=(starATsyt2-1);
endFATsyt2=endFATsyt2(2:end); % End of Activation

Best Answer

dT = 0.1;
mask = (T.ATSys.signals.values(:)==2).'; %row vector
starts = strfind([false mask], [false true]);
stops = strfind([mask false], [true false]);
activation_durations = dT * (stops - starts + 1);
%an activation of 1 sample would have equal stop and start so difference would be 0, but that should be considered 1 timestep
activation_times = arrayfun(@(start,stop) (start:stop)*dT, starts, stops, 'uniform', 0); %this assumes first time is dT not 0
Now, activation_durations is a vector of durations (minimum dT for an activation of one point duration), and activation_times is a cell array of the timestamps of activations, if you need that for some reason (for example you might need it if you were doing curve fitting.)