n = 1000000; observe = 2; % Naive way % 1 actual = randn(n, 1) * 4; offset = randn(n, 1) * 3; measured = actual + offset; % 2 antecedent = observe - .1 < measured & measured < observe + .1; % 3 % hist(actual(antecedent)) % mean(actual(antecedent)) % Less naive way % 1 actual = randn(n, 1) * 4; offset = observe - actual; weight = normpdf(offset, 0, 3); % 3 % sum(actual .* weight) / sum(weight) % total = sparse(floor(actual)-min(floor(actual))+1, ones(size(actual)), weight); % plot(min(floor(actual)):max(floor(actual)), total) % Even less naive way -- towards Kalman filtering % (http://www.cs.unc.edu/~welch/kalman/maybeck.html) actual = -20:.1:20; offset = observe - actual; weight = normpdf(actual, 0, 4) .* normpdf(offset, 0, 3);