function P=FtoP(F,p)
%INPUT:  F    cell with r matrices of size m by n
%        p    probability distribution size r
%OUTPUT: P    corresponding Choi matrix P 
r=length(F);
[m n]=size(F{1});
mn=m*n;
P=zeros(mn);
for jj=1:n,               % by column
	for ii=1:jj,       % down each column
		temp=0;
		for rr=1:r,
			temp=temp+p(rr)*(F{rr}(:,ii))*(F{rr}(:,jj))';
		end
		if ii==jj,
			temp=(temp+temp')/2;
		        P((ii-1)*m+1:ii*m,(jj-1)*m+1:jj*m)=temp;
		else
		        P((ii-1)*m+1:ii*m,(jj-1)*m+1:jj*m)=temp;
		        P((jj-1)*m+1:jj*m,(ii-1)*m+1:ii*m)=temp';
		end
	end
end
