Create new matrix based on an existing one

3 visualizzazioni (ultimi 30 giorni)
FC93
FC93 il 6 Mar 2017
Commentato: FC93 il 6 Mar 2017
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.

Risposta accettata

Jan
Jan il 6 Mar 2017
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(:), :);

Più risposte (0)

Categorie

Scopri di più su Entering Commands in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by