MATLAB: Do I get “Array indices must be positive integers or logical values”

array

delta_x = 2/40;
x = [];
for i = 1:1:41
x = x (i-1) * delta_x;
end

Best Answer

Yes because index has to be positive where your loop starts from 1 if you index x as i-1 it means it’s zero that’s why the error arises. An example:
delta_x = 2/40;
x = [1:41];
for i = 1:length(x)
x(i) = x(i)*delta_x;
end
x