필터 지우기
필터 지우기

How do i band a vector into sized brackets

조회 수: 3 (최근 30일)
Nick Keepfer
Nick Keepfer 2018년 2월 13일
댓글: Star Strider 2018년 2월 13일
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.
  댓글 수: 2
Nick Keepfer
Nick Keepfer 2018년 2월 13일
The former is what I wanted, thank you very much, works like a dream!
Star Strider
Star Strider 2018년 2월 13일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (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