MATLAB: Subscript indices must either be real positive integers or logicals. error How it can be resolved ?

vektor=zeros(1453,1453);
satir=0;
eleman=0;
for satir=0:1:1453
for eleman=0:1:1453
vektor(satir,eleman) = factorial(satir)/factorial(eleman)*factorial(satir-eleman);
end
end
disp('vektor',vektor)

Best Answer

for satir=0:1:1453
for eleman=0:1:1453
vektor(satir,eleman) = ...
In the first iteration you get:
vektor(0, 0) = ...
This cannot work, because indices start at 1 in Matlab.
This is the meaning of the error message. If you take the time to search for this message in the forum before you ask, you will find hundreds of threads concerning this problem.
A solution could be:
vektor(satir + 1, eleman + 1) = ...
  • Note 1: disp('vektor',vektor) will fail, because disp() accepts 1 input only. Try:
disp('Vektor:')
disp(vektor)
  • Note 2: What do you expect as output of factorial(1453)? The double number will overflow much earlier. The documentation explains:
the answer is only accurate for N <= 21
factorial(171) is Inf already.
Related Question