How to Pad an Array with extra zeros
古いコメントを表示
Say I have an array, and I use to reshape function to divide it into equal sections. In the case that it cannot be divided into equal sections, how do I add zeros at the end to compensate? Say A=[1 8 1 9 1 4 1 5 0 4], and I want to divide it into sections of 4. 4 is not a set value.
採用された回答
その他の回答 (2 件)
Andrei Bobrov
2017 年 10 月 23 日
編集済み: Andrei Bobrov
2017 年 10 月 23 日
A=[1 8 1 9 1 4 1 5 0 4];
n = 4;
B = reshape([A(:);zeros(mod(-numel(A),n),1)],n,[])';
doc padarray
B = [A zeros(1,2)]
カテゴリ
ヘルプ センター および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!