How do i band a vector into sized brackets

3 次查看(过去 30 天)
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 :)

采纳的回答

Star Strider
Star Strider 2018-2-13
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by