How do i band a vector into sized brackets

2 visualizaciones (últimos 30 días)
Nick Keepfer
Nick Keepfer el 13 de Feb. de 2018
Comentada: Star Strider el 13 de Feb. de 2018
I have a matrix R(i,j), where R(i,:) gives the positions of several objects at a given timestep j.
Say I have at a given timestep R(i,:) = [1 2 3 4 5 6 7] and I wish to create bands where I could collect terms say between 1-3 and 4-7.
i.e Something that would pull R(i,j) into two seperate arrays where one contains the values between 1-3 and another with the values 4-7, keeping the timesteps intact.
Can anyone think of an easy way to do this?
Thanks in advance :)

Respuesta aceptada

Star Strider
Star Strider el 13 de Feb. de 2018
I am not certain what you are referring to.
Two possibilities:
R(i,:) = [1 2 3 4 5 6 7];
V1{i} = R(i, (R(i,:)>=1) & (R(i,:)<=3)) % Testing For Values (Cell Array)
V2{i} = R(i, (R(i,:)>=4) & (R(i,:)<=7)) % Testing For Values (Cell Array)
X1(i,:) = R(i,1:3) % Addressing Columns
X2(i,:) = R(i,4:7) % Addressing Columns
The first set test for element values within the range.
The second set simply addresses the appropriate columns. Note that you can do that with the entire matrix at once, rather than row-by-row.
  2 comentarios
Nick Keepfer
Nick Keepfer el 13 de Feb. de 2018
The former is what I wanted, thank you very much, works like a dream!
Star Strider
Star Strider el 13 de Feb. de 2018
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown 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!

Translated by