How Zero padding inside a matrix ?
    2 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Hello, how can i zero pad inside a matrix ? For example :
if true
  % code
end
A = [ 1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16]
And i want 
A = [ 1 2 3 4
    5 6 7 8
    0 0 0 0
    0 0 0 0
    ......
    0 0 0 0 
    0 0 0 0
    9 10 11 12
    13 14 15 16]
I know padarray can zero pad but only outside not in the inside.. Thank you.
0 件のコメント
採用された回答
  Star Strider
      
      
 2016 年 5 月 17 日
        Create a second matrix of zeros, then assign the appropriate rows of your first matrix to the rows you want in the second matrix:
A = [ 1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16];
Desired_Rows = 10;                                          % Pick A Number
B = zeros(Desired_Rows, size(A,2));
B([1:2 end-1:end],:) = A
B =
       1     2     3     4
       5     6     7     8
       0     0     0     0
       0     0     0     0
       0     0     0     0
       0     0     0     0
       0     0     0     0
       0     0     0     0
       9    10    11    12
      13    14    15    16
6 件のコメント
  Guillaume
      
      
 2016 年 5 月 17 日
				In my opinion, it'd be simpler to split the original matrix and insert a zero matrix in between: B = [A(1:10, :); zeros(40, size(A, 2); A(11:20, :)]
  Star Strider
      
      
 2016 年 5 月 17 日
				I thought about that, but considered that this could be a ‘proxy problem’ and the rows could end up being inserted anywhere in the target matrix, not just at the ends. The approach I took allows for that more easily.
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

