i want to fill zeros inbetween vector elements
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!