i want to fill zeros inbetween vector elements

4 ビュー (過去 30 日間)
Mohamed Ayman
Mohamed Ayman 2019 年 10 月 16 日
回答済み: Bjorn Gustavsson 2019 年 10 月 16 日
i have two vectors i want to fill zeros inbetween the first one elements according to the values in the second one
for emaple
v1=[687
345
7584
4513]
v2=[0
40
120
360] so i want to fill 39 zeroes between 687 and 345 and 79 zeros between 345 and 7584 and 239 zeros between 7584 and 4513 and so on for 80000 samples

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 10 月 16 日
Looks like you should turn to matlab's sparse arrays. Something like this should be a shortest-ish code-snippet to do what you need:
v2(1) = 1; % To shift the index of your first element, maybe you should shift all by one...
v_zero_filled = sparse(ones(size(v1)),v2,v1));
Maybe you want a non-sparse array:
v_zero_filled = full(v_zero_filled);
HTH

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by