Creating subvectors from a vector

5 ビュー (過去 30 日間)
Molepo Alfred
Molepo Alfred 2020 年 7 月 18 日
コメント済み: the cyclist 2020 年 7 月 18 日
Greetings of the day!
I have a vector X of length L. I would like to create multiple vectors from it using
X(i)=[X(mx0+b),X(mx1+b),X(mx2+b)....X(mxk+b)] where b=0,1,2,3,... m-1. where m is the number of sub vectors, k=L/m.
For example if m=4 and
X=[0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15];
then the output should be the following.
[0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15]

採用された回答

the cyclist
the cyclist 2020 年 7 月 18 日
編集済み: the cyclist 2020 年 7 月 18 日
reshape(X,[],4)
See the documentation for reshape for details. The empty square brackets there indicate that MATLAB should infer the length of the first dimension from the size of X (just as you want).
  2 件のコメント
Molepo Alfred
Molepo Alfred 2020 年 7 月 18 日
Thank you very much for the explannation.
the cyclist
the cyclist 2020 年 7 月 18 日
It wasn't perfectly clear to me if you wanted k-by-4 or 4-by-k, since you happened to choose a 4-by-4 example, so you might need
reshape(X,4,[])
instead.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by