Create a new vector with even numbers first.

조회 수: 8 (최근 30일)
Michael Noak
Michael Noak 2019년 10월 20일
답변: ABHILASH SINGH 2019년 10월 20일
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.

답변 (1개)

ABHILASH SINGH
ABHILASH SINGH 2019년 10월 20일
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)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by