If the first column contains non-repeated integers, you can use accumarray
, which lets you specify the fill value (I'm using NaN
):
result = [(min(A):max(A)).' accumarray(A(:,1)-min(A(:,1))+1, A(:,2), [], @sum, NaN)];
Alternatively, you can use ismember
:
indices = min(A(:,1)):max(A(:,1));
result = [indices(:) NaN(numel(indices), 1)];
result(ismember(indices, A(:,1) ),2) = A(:,2);
Either of the above gives
result =
101.0000 14.8700
102.0000 NaN
103.0000 NaN
104.0000 18.2300
105.0000 NaN
106.0000 NaN
107.0000 NaN
108.0000 NaN
109.0000 NaN
110.0000 19.0300
111.0000 NaN
112.0000 NaN
113.0000 19.8400