フィルターのクリア

zero padding between data

14 ビュー (過去 30 日間)
fima v
fima v 2020 年 4 月 4 日
コメント済み: Les Beckham 2020 年 4 月 4 日
Hello, i have a vector shown bellow, how do i insert two zeros in between every bumber as shown bellow.
Thanks.
a=[1,2,3,4]
a=[1,0,0,2,0,0,3,0,0,4]

採用された回答

Sriram Tadavarty
Sriram Tadavarty 2020 年 4 月 4 日
Hi Fima,
You can perform this task in many ways, one simple way is this:
% Assign a variable with zeros for the length of the output
out = zeros(10,1);
out(1:3:end) = a;
Hope this helps.
Regards,
Sriram
  2 件のコメント
fima v
fima v 2020 年 4 月 4 日
Hello , it works. What i the logic in this?
it looks to me as if we insert vector "a" every third place,which is not what it does in reality.
what is the logic functionaly of this line ?
out(1:3:end) = a;
Thanks.
Les Beckham
Les Beckham 2020 年 4 月 4 日
I had to look at this for a while to figure out why it works as well.
I will try to explain. The line
out(1:3:end) = a;
works because out(1:3:end) is the same as out([1 4 7 10]) and so is a 4 element vector. The vector a is also a 4 element vector and thus the assignment works, with each element of the right hand vector being assigned into the corresponding element of the left hand vector.
Here is a version that isn't so hard-coded. It supports different sized input vectors and different numbers of 'padding' zeros.
% Inputs - change as desired
a = [1 2 3 4];
pad_size = 2;
% Process the inputs
initial_size = numel(a);
final_size = initial_size + (pad_size * (initial_size - 1));
% Assign a variable with zeros for the final size of the output
out = zeros(1,final_size); % modified to be a row instead of a column
out(1:pad_size+1:end) = a;
out % display the result

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by