MATLAB Answers

0

i want to fill zeros inbetween vector elements

Asked by Mohamed Ayman on 16 Oct 2019
Latest activity Answered by Bjorn Gustavsson on 16 Oct 2019
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

  0 Comments

Sign in to comment.

1 Answer

Answer by 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

  0 Comments

Sign in to comment.