How to split a vector into 2 vectors, that one holds the evens and one hold the odds

조회 수: 22 (최근 30일)
I have this vector
0.0492
1.0000
0.9508
1.0000
1.0410
-0.0000
-0.0410
-0.0000
and I want to split it into
X = [0.0492 , 0.9508 , 1.0410 , -0.0410]
Y = [1, 1, 0 , 0]
thanks you
Kpyr
  댓글 수: 1
HWIK
HWIK 2021년 11월 27일
How do you want to split them between even and odd if most of them are not integers? According to the last digit?

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

채택된 답변

DGM
DGM 2021년 11월 27일
편집: DGM 2021년 11월 27일
Something like this will extract the contents of odd/even indices:
V = 1:10;
odds = V(1:2:end)
odds = 1×5
1 3 5 7 9
evens = V(2:2:end)
evens = 1×5
2 4 6 8 10
Note that's not necessarily odd/even values

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by