how to padding array with zeros to limit rows (I can choose the limit)
1 次查看(过去 30 天)
显示 更早的评论
I have a data with 2 columns
AB=[1 6
2 7
3 8
4 9
5 10]
So, I want to (padding) with zeros to rows number 21, so the result will be
AB=[1 6
2 7
3 8
4 9
5 10
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0]
0 个评论
采纳的回答
Walter Roberson
2022-6-30
[AB; zeros(21-size(AB, 1),size(AB, 2))]
1 个评论
Walter Roberson
2022-6-30
In the special case where you know that AB is smaller than desired you can just use
AB(21,end)=0;
Do not use this if AB might already be large enough.
更多回答(1 个)
Voss
2022-6-30
AB=[1 6
2 7
3 8
4 9
5 10];
AB(21,:) = 0; % MATLAB fills the intervening rows with zeros
disp(AB);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!