function [p,inds] = getPX(P,m,n,X,ii) % p = P(X(ii) = x) % works for all distrubutions P on m^n if length(ii)==0 p = 1; return end dims = repmat([m],[1 n]); v = repmat({1:m},[1 n]); for j=1:length(ii) v{ii(j)} = X(j); end xx = list_all_ind_g(v); inds = coord2ind(xx,dims); p = sum(P(inds)); return