Algorithm that identifies the number of time steps in which a matrix has certain values?

1 view (last 30 days)
I have a 4001x1 matrix ODv (attached) and its 1x4001 timespan vector. As you can see in the attached image, every x milliseconds there is an action potential (in this case, they are the 4 bursts of activity you see where the y value increases from approximately -60mV to positive values).
I am looking for a way to measure how many milliseconds it takes for each action potential (whose number is variable, it might become 5 or 2 or whatever number depending on the conditions) to go from a value of -40mV (this number is the same for all 4 action potentials) to each peak value (this number changes for each action potential: approximately 40, 30, 30 and 30 mV in this image).
So for example I'd need an algorithm that tells me: it took 2 ms for the first AP, 3 ms for the second AP, 1 ms for the third AP and so on.
I would know how to do this for one AP, but not when there is more than one.
Thanks!
  3 Comments
Atsushi Ueno
Atsushi Ueno on 17 Apr 2021
This is a simple "findpeaks" function. However, it is only very ad hoc. Does it satisfy your purpose?
thr = -20; % for this ODv.mat only
peaks = ODv(1:end-2) < ODv(2:end-1) ...
& ODv(2:end-1) > ODv(3:end) ...
& ODv(2:end-1) > thr;
idx = find(peaks);

Sign in to comment.

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 17 Apr 2021
load('time.mat');
load('ODv.mat');
thr = -20; % for this ODv.mat only
thr2 = 2; % for this ODv.mat only
peaks = ODv(1:end-2) < ODv(2:end-1) ...
& ODv(2:end-1) > ODv(3:end) ...
& ODv(2:end-1) > thr;
botms = diff(diff(ODv) > thr2) == 1;
peak_time_span = tspan(find(peaks)) - tspan(find(botms));
peak_time_span =
0.6500 0.7250 0.7250 0.7250 0.7250

More Answers (1)

Cris LaPierre
Cris LaPierre on 17 Apr 2021
If you use a live script, you also can develop your own algorithm to find the points you want interactively using the Find Local minima and maxima live task. You do not need any toolboxes to use it.
It will return the indices of the peaks. Assuming you have vector of times as well, you can use that to find the corresponding times. From there, you can take the difference between the times (diff).

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by