Filling blanks with zeros

조회 수: 1 (최근 30일)
Shawn Imming
Shawn Imming 2016년 11월 7일
댓글: Shawn Imming 2016년 11월 7일
Hello, I have a vector of 1175 values. The vector begins with the following values: 1983, 2004, 2054, 2094, 3107, 3137 etc. Is it possible to fill in the blanks between the values with zeros? So it would be 1982 times 0, than the value 1983, 21 times 0, than the value 2004, 50 times 0, than the value 2054 and so on...
Thanks in advance! Shawn Imming

채택된 답변

Walter Roberson
Walter Roberson 2016년 11월 7일
maxval = max(YourVector);
NewVector = zeros(1, maxval);
NewVector(YourVector) = YourVector;
  댓글 수: 1
Shawn Imming
Shawn Imming 2016년 11월 7일
Thanks this works great!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2016년 11월 7일
편집: KSSV 2016년 11월 7일
clc; clear all ;
yrs = [ 1983, 2004, 2054, 2094, 3107, 3137];
data = rand(1,length(yrs)) ; % respective values
[yrs' data']
y = min(yrs):max(yrs) ;
datai = zeros(size(y)) ;
datai(ismember(y,yrs)) = data ;
[y' datai']

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by