Azzera filtri
Azzera filtri

How do i band a vector into sized brackets

3 visualizzazioni (ultimi 30 giorni)
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 :)

Risposta accettata

Star Strider
Star Strider il 13 Feb 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 Commenti
Nick Keepfer
Nick Keepfer il 13 Feb 2018
The former is what I wanted, thank you very much, works like a dream!
Star Strider
Star Strider il 13 Feb 2018
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by