Filling blanks with zeros

3 visualizaciones (últimos 30 días)
Shawn Imming
Shawn Imming el 7 de Nov. de 2016
Comentada: Shawn Imming el 7 de Nov. de 2016
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Nov. de 2016
maxval = max(YourVector);
NewVector = zeros(1, maxval);
NewVector(YourVector) = YourVector;

Más respuestas (1)

KSSV
KSSV el 7 de Nov. de 2016
Editada: KSSV el 7 de Nov. de 2016
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']

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by