You're overwriting the matrix Cmd every iteration because of the line Cmd=zeros(M:D). Take it outside of both for loops.
M=input('Enter number of manufacturers: ');
D=input('Enter number of distributers: ');
O=1; T=1; R=1; Z=1;
Cmd(m,d)=input('Enter traveling cost for manufacturer to distributer: ');
To sum over all the elements of the matrix you can use sum(Cmd(:)).