Create new matrix based on an existing one

3 ビュー (過去 30 日間)
FC93
FC93 2017 年 3 月 6 日
コメント済み: FC93 2017 年 3 月 6 日
I have a big matrix. Now I want to create a new matrix that takes the first value in each column and changes the following 11 values with the fist value. Then I want to take the value of the 13th row for each column and put in in the following 11 rows for each column.
An example for a column:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
I would like to change it to:
1 1 1 1 1 1 1 1 1 1 1 1 13 13 13 13 13 13 13 13 13 13 13 13
This would be an example for a small column. My matrix has the dimension of 253X7690.
Thank you for your help.

採用された回答

Jan
Jan 2017 年 3 月 6 日
A = rand(253, 7690);
B = A(1:12:end, :); % Take every 12th row
C = repelem(B, 12, 1); % Needs Matlab >= 2015a
With older Matlab versions:
Index = repmat(1:12:size(A, 1), 12, 1);
C = A(Index(:), :);
  1 件のコメント
FC93
FC93 2017 年 3 月 6 日
Thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by