フィルターのクリア

how to padding array with zeros to limit rows (I can choose the limit)

1 回表示 (過去 30 日間)
abdullah al-dulaimi
abdullah al-dulaimi 2022 年 6 月 30 日
コメント済み: Voss 2022 年 6 月 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]

採用された回答

Walter Roberson
Walter Roberson 2022 年 6 月 30 日
[AB; zeros(21-size(AB, 1),size(AB, 2))]
  1 件のコメント
Walter Roberson
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
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);
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
  2 件のコメント
abdullah al-dulaimi
abdullah al-dulaimi 2022 年 6 月 30 日
thank you so much for your answer
Voss
Voss 2022 年 6 月 30 日
You're welcome!

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by