MATLAB: Do I get the error “Subscript indices must be real positive integers or logicals?”

error

for k=1:length(x)
d=T(V)-Dft(V)-Dw(V);
end
max = max(d);

Best Answer

Your line
max = max(d);
first calls upon the built in MATLAB function max to find the maximum of d. It then redefines the name max to be associated with a variable with that value, blocking the use of max as a function. The next time you attempt to take max() of anything, max(d) would be interpreted as an attempt to index the variable named max with the index given in d, which can only work if d is the value true or false or is something numeric that consists entirely of 1's.
Related Question