MATLAB Answers

Create a new vector with even numbers first.

14 views (last 30 days)
Michael Noak
Michael Noak on 20 Oct 2019
Answered: ABHILASH SINGH on 20 Oct 2019
I have a vector = [20 21 22 23 24 25 26 27 28 29]
My task is to create a new vector from the first, with the even numbers first and then the odd numbers = [20 22 24 26 28 21 23 25 26 27 28 29]
Last I have to make it the Dame way but Vice versa.

  0 Comments

Sign in to comment.

Answers (1)

ABHILASH SINGH
ABHILASH SINGH on 20 Oct 2019
x = [20 21 22 23 24 25 26 27 28 29]
% Find indices where x is even:
evenIndices = rem(x, 2) == 0
% Extract only the even numbers into a new vector.
allTheEvenNumbers = x(evenIndices)

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags

Products


Release

R2019a