Create new matrix based on an existing one

3 次查看(过去 30 天)
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(:), :);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by