MATLAB does not use range() . Your second version is correct.
However, you will probably want to store the results of each iteration. In this case you would have to store into Output(X+11, Y+11) . In the more general case where you might not be incrementing by 1, you should learn a different pattern:
xvals = -10:.12345:10;
nx = length(xvals);
yvals = randn(size(xvals));
ny = length(yvals);
Output = zeros(nx, ny);
for xidx = 1 : nx
x = xvals(xidx);
for yidx = 1 : ny
y = yvals(yidx);
...
Output(xidx, yidx) = ...
end
end
with this general pattern, the values to be processed do not have to be consecutive or even ordered, but this code will handle all of the combinations.
Best Answer