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

21 views (last 30 days)
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 Comment
HWIK
HWIK on 27 Nov 2021
How do you want to split them between even and odd if most of them are not integers? According to the last digit?

Sign in to comment.

Accepted Answer

DGM
DGM on 27 Nov 2021
Edited: DGM on 27 Nov 2021
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

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!