How would I create an even and odd matrix within a specific range?
14 ビュー (過去 30 日間)
古いコメントを表示
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!
0 件のコメント
回答 (3 件)
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 件のコメント
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!