i want to fill zeros inbetween vector elements

7 views (last 30 days)
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

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 16 Oct 2019
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

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!