How do I find the number of occurrences of data points between specific values in a matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Joe
el 9 de Dic. de 2015
Comentada: Joe
el 14 de Dic. de 2015
The following code finds the number of occurrences of data between two points of the same value.
x=[4 1 2 2 2 2 2 2 2 2 2 4 1 2 2 2 2 3 3 4 5 6 1 2 2 2 2 2 2 2 2 2 2 2 3 4 1 2 2 2 2 2];
t=data==8;
out=diff(find(t))-1;
How could one change this code to determine how many data points are between specified data points to choose between?
for example:
If I had this code and I wanted to find the interval between the "1" and the next "4" in sequence how would I go about doing it? I want the code to output the interval of data points between the two specific values for each of the occurrences. From the data given as X the output should be output=[9 6 12]
Any help would be appreciated
2 comentarios
dpb
el 9 de Dic. de 2015
How much is known of the data structure a priori? Specifically, is it known the values exist in sequence as shown here (albeit a missing closing '4' after the last initial '1')?
Respuesta aceptada
Andrei Bobrov
el 14 de Dic. de 2015
data = [1 2 2 2 2 2 2 2 2 2 3 1 2 2 2 2 7 8 3 8 3 4 5 6 1 2 2 2 ...
2 2 2 2 2 2 2 2 3 4 1 2 2 2 2 2];
x = [1 3];
[l1,ii] = ismember(data,x);
i0 = find(l1);
k = strfind(ii(i0),[1 2]);
out = diff([i0(k);i0(k+1)])-1;
Más respuestas (0)
Ver también
Categorías
Más información sobre Resizing and Reshaping Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!