How can I replicate this matrix

3 Ansichten (letzte 30 Tage)
Ede gerlderlands
Ede gerlderlands am 18 Dez. 2012
I have F= 20x12 matrix and I want to get F2 =62x12 matrix in such away that The each element of F(20X12)is replicated by 3 and the last value has to be replicated 5 times so as to have 62x12 data
here is the matrix I worked upon and failed
for k =size(F,1);
a=repmat(F,3,1);
F2=[a(:);ones(2,1)*a(end)]
end;
but couldn't succeed..any help is highly appreciated

Akzeptierte Antwort

Pedro Villena
Pedro Villena am 18 Dez. 2012
Bearbeitet: Pedro Villena am 18 Dez. 2012
n=3; %%three times
m=2; %%plus two times for the final row
F2 = [];
for k=1:size(F,1),
F2 = [F2; repmat(F(k,:),n,1)];
end
F2 = [F2; repmat(F(end,:),m,1)];

Weitere Antworten (2)

Walter Roberson
Walter Roberson am 18 Dez. 2012
F2 = [repmat(F, 3, 1), F([end end], :)];
  2 Kommentare
Ede gerlderlands
Ede gerlderlands am 18 Dez. 2012
Thanks, but this replicate the entire F three times not each element of 'F' successively and that's what I want?
Walter Roberson
Walter Roberson am 18 Dez. 2012
F2 = [kron(F, ones(3, 1)); F([end end], :)];

Melden Sie sich an, um zu kommentieren.


Daniel Shub
Daniel Shub am 18 Dez. 2012
I like questions that can be answered with one-liners ...
F([reshape(repmat(1:length(F), 3, 1), 3*length(F), 1); repmat(length(F), 2, 1)], :)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by