Find the index of the elements that are between two radii

2 visualizaciones (últimos 30 días)
Maryam S
Maryam S el 20 de Feb. de 2019
Comentada: Maryam S el 21 de Feb. de 2019
Hi,
I have 15 channels of 16 m width with the following internal and external radii:
initial_r = [ 60 76 93 109 125 142 158 174 191 207 223 240 256 272 289 305 ]
I mean there is a channel of 16 m between 60 m and 76 m and so on.
There are particles in these channels that their position change as a function of time, for instance after 10 seconds the position of a particle with the above vector of initial position can be :
Final_r = [ 68 110 70 74 92 192 155 172 170 200 202 204 305 305 305 305 ]
I should find the index of the initial position of the particles that their final position lay in the same channels. for example, there are particles with 3 different initial positions that change to the same final position: 60 m < (68 m, 70 and 74 m) < 76 m, and also there is only one stream with the fianal position between 76 m and 93 m (92 m). I can find how many streams have the same final position but I cannon find the index of which ones. I need a tool that returns me vectors of indices, for instance, for the three streams with the same final position of 60-76 the indices are: index = [1 3 4], or for the one between 76-93 index = [5] but how to find it?
Thanks

Respuesta aceptada

Matt J
Matt J el 21 de Feb. de 2019
Editada: Matt J el 21 de Feb. de 2019
Perhaps this is what you want?
G=discretize(Final_r,initial_r);
Indices = accumarray(G.',(1:numel(Final_r)).',[],@(z) {sort(z).'})
So what this gives is a cell array such that Indices{k} are the indices of streams belonging to the k-th channel, e.g.,
>> Indices{1}
ans =
1 3 4

Más respuestas (1)

Matt J
Matt J el 21 de Feb. de 2019
Editada: Matt J el 21 de Feb. de 2019
index = (Final_r>=initial_r) & (Final_r<[initial_r(2:end),inf])
  1 comentario
Maryam S
Maryam S el 21 de Feb. de 2019
Editada: Maryam S el 21 de Feb. de 2019
Thanks Matt J for the quick answer, but I think I did not well explain what I meant. I edited my question, tak a look if you are still interested in helping with me.
Thanks
Maryam

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by