フィルターのクリア

Padding a vector with zeros

3 ビュー (過去 30 日間)
L'O.G.
L'O.G. 2022 年 8 月 30 日
コメント済み: James Tursa 2022 年 8 月 30 日
How do I pad a vector of type double so that there are say 5 elements with zeros after every 3rd element in the original vector?
For a simple example:
A = [1 2 0.3 2.4 20.3 1.111 6.3 7.1 44];
I want to have
B = [1 2 0.3 0 0 0 0 0 2.4 20.3 1.111 0 0 0 0 0 6.3 7.1 44 0 0 0 0 0];

採用された回答

David Hill
David Hill 2022 年 8 月 30 日
A = [1 2 0.3 2.4 20.3 1.111 6.3 7.1 44];
b=reshape(A,3,[]);
b=[b;zeros(5,size(b,2))];
B=b(:)';
  1 件のコメント
James Tursa
James Tursa 2022 年 8 月 30 日
The third line above could also just be:
b(end+5,end) = 0;

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by