How would I create an even and odd matrix within a specific range?

조회 수: 4 (최근 30일)
Amanda Mnt
Amanda Mnt 2017년 1월 23일
So I want to make a matrix where in the first column I would have even numbers within the range of (32,44] and the second column be odd numbers within that range as well. How would I be able to generate a matrix that would do that besides just putting A=[34 33; 36 35; 38 37; 40 39; 42 41; 44 43].
Thank you very much!

답변 (3개)

Jorge Mario Guerra González
Jorge Mario Guerra González 2017년 1월 23일
편집: Jorge Mario Guerra González 2017년 1월 23일
Like this
lower=32;
upper=44;
A=lower+2:2:upper;
B=lower+1:2:upper;
result=[A;B]
  댓글 수: 2
Amanda Mnt
Amanda Mnt 2017년 1월 23일
This was very helpful and it works when asked for columns! However, I was wondering about rows.

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


Walter Roberson
Walter Roberson 2017년 1월 23일
[(34:2:44).', (33:2:43).']

Star Strider
Star Strider 2017년 1월 23일
Another approach:
v = 32:44;
A2 = (v(rem(v,2) == 1))';
A1 = (v(rem(v,2) == 0))';
A = [A1(2:end) A2]
A =
34 33
36 35
38 37
40 39
42 41
44 43

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by