フィルターのクリア

Repeat rows in a matrix

32 ビュー (過去 30 日間)
Tommaso Fornaciari
Tommaso Fornaciari 2016 年 11 月 16 日
回答済み: Changoleon 2016 年 11 月 16 日
Hello, I have a 7832x20 matrix(A) and and I would like to create another identical sized matrix(B) where the first 22 rows of B are equal to the first row of A, the 23rd up to the 44th row of B to be equal to the 23rd row of A...rows 45 to 66 of B equal to row 45 and ,I think you got the point,until the last row. I have tried the following code but I get a dimension mismatch error
for mm=1:22:7832
B(mm,:) = padarray(A(mm,:),[21],'replicate','post')
end
Is there anotherway to do it? Am I completely off? I thank you in advance for your help

回答 (3 件)

Guillaume
Guillaume 2016 年 11 月 16 日
B = repelem(A(1:22:end, :), 22, 1);
is all that is needed. repelem was introduced in R2015a.
  2 件のコメント
Tommaso Fornaciari
Tommaso Fornaciari 2016 年 11 月 16 日
worked! thank you. cheers
Image Analyst
Image Analyst 2016 年 11 月 16 日
You can also "thank" him by voting for, and Accepting, his answer to give him reputation points.

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


Honglei Chen
Honglei Chen 2016 年 11 月 16 日
B = kron(A(1:22:end,:),ones(22,1))

Changoleon
Changoleon 2016 年 11 月 16 日
Hi, I got really really close to the answer. You just need to add 2 or 3 lines of code to finish it.
A = [ 1 2; 3 4; 5 6; 7 8; 9 10; 11 12; 13 14; 15 16; 17 18; 19 20];
d=2;
for i = 1:2:10
B(i,:) = A(i,:);
for j=1:1:9
if B(j,1)==0
B(j,:) = B(j-1,:);
end
end
end

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by