What's wrong in this code? why is this not displaying whole matrix?and how to sum whole matrix?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Aimen Mujahid
am 22 Feb. 2017
Kommentiert: Aimen Mujahid
am 22 Feb. 2017
M=input('Enter number of manufacturers'); D=input('Enter number of distributers'); O=1; T=1; R=1; Z=1; for m=1:M; for d=1:D; Cmd=zeros(M:D); Cmd(m,d)=input('Enter traveling cost for manufacturer to distributer'); disp(Cmd); end end
0 Kommentare
Akzeptierte Antwort
Rahul Kalampattel
am 22 Feb. 2017
Bearbeitet: Rahul Kalampattel
am 22 Feb. 2017
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=zeros(M:D);
for m=1:M
for d=1:D
Cmd(m,d)=input('Enter traveling cost for manufacturer to distributer: ');
disp(Cmd);
end
end
To sum over all the elements of the matrix you can use sum(Cmd(:)).
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!