how can I increase the size of an incremental vector filling the space with zeros
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi, I have an incremental vector of lenght 5
a = [1 5 8 11 14]
I want to stretch a and create a new vector of length 14 in which all the empty positions between the values of a are replaced by zeros
b = [1 0 0 0 5 0 0 8 0 0 11 0 0 14]
I have already tried interpolation but doesn't seem to work
Any suggestion is very much appreciated
댓글 수: 0
채택된 답변
Abolfazl Chaman Motlagh
2022년 6월 19일
use ismember function.
X = cumsum(randi(3,1,5))
Y = 1:X(end);
Y = ismember(Y,X).*Y
추가 답변 (1개)
Image Analyst
2022년 6월 19일
The accepted answer might work but I think it's complicated and the simpler answer is to just do this:
a = [1 5 8 11 14];
b(a) = a
I mean, how much simpler could it be? If you like my answer, you can vote for it.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!