フィルターのクリア

Taking every nth element from each column in a matrix

761 ビュー (過去 30 日間)
Henry Hallock
Henry Hallock 2014 年 12 月 18 日
コメント済み: Jianming Yuan 2021 年 6 月 3 日
Hello,
I have a 10x5 matrix:
A = randi(10,10,5);
A =
2 8 7 1 4
9 8 8 1 7
4 8 2 8 8
3 3 2 10 6
8 7 6 7 8
1 6 5 2 3
1 4 9 8 8
7 1 8 2 10
7 8 8 2 9
6 4 1 7 1
I would like to make another matrix (B) that contains every 2nd element from each column of A, such that
B =
9 8 8 1 7
3 3 2 10 6
1 6 5 2 3
7 1 8 2 10
6 4 1 7 1
Thank you.

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 12 月 18 日
Henry - try grabbing every other row as
B = A(2:2:end,:);
In the above we use 2:2:end to start at row two and consider every other row thereafter (with the second 2) until we reach the end of the rows. The second parameter, :, indicates that we want all column data.
Try the above and see what happens!
  8 件のコメント
Jonathan Harding
Jonathan Harding 2021 年 2 月 20 日
Amazing
Jianming Yuan
Jianming Yuan 2021 年 6 月 3 日
excellent

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by