MATLAB Answers

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

조회 수: 1(최근 30일)
Samuele Bolotta
Samuele Bolotta 2021년 4월 17일
답변: Atsushi Ueno 2021년 4월 17일
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
Atsushi Ueno
Atsushi Ueno 2021년 4월 17일
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);

댓글을 달려면 로그인하십시오.

채택된 답변

Atsushi Ueno
Atsushi Ueno 2021년 4월 17일
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

추가 답변(1개)

Cris LaPierre
Cris LaPierre 2021년 4월 17일
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