i want to fill zeros inbetween vector elements
이전 댓글 표시
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
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
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!