Subscript Indices error in nested for loop?

1 view (last 30 days)
Elena
Elena on 9 Apr 2014
Edited: Jan on 10 Apr 2014
Hi all. I am performing an interpolation of certain areas of a gird and I have the interpolation function within a nested for loop.
indXStart = [15, 46, 76, 110]; %initial x position of WT cube
indXStop = [29, 60, 80, 124];
indYStart = [11, 31, 51, 71, 91, 111]; %initial y position of WT Cube
indYStop = [21, 41, 61, 81, 101, 121];
for T = 1:6 %Timesteps of first hour, in 10min increments
for W = 1:24 %All 24 windturbines
for z = 7:23 %from height of 7u to 23
a = z - 6
for ix = 1:4
for iy = 1:6
NewMesh.WT(W).step(T).u(:,:,a) = WT_Interp(X(indXStart(ix)), X(indXStop(ix)), ... Y(indYStart(iy)), Y(indYStop(iy)), X(indXStart(ix):indXStop(ix)), ...
Y(indYStart(iy):indYStop(iy)), ... Horiz.step(T).u(X(indXStart(ix):indXStop(ix)),...
Y(indYStart(iy):indYStop(iy)),z))
end
end
end
end
end
Matlab is giving me a "subscript indices must either be real positive integers or logicals" error and I can't figure out why. WT_Interp is the function where I have the interpolation code. Any ideas or suggestions on how to fix this?
  2 Comments
dpb
dpb on 9 Apr 2014
Use debugger and work thru it...
Jan
Jan on 10 Apr 2014
Edited: Jan on 10 Apr 2014
I you post a copy of the complete error message, we would be able to see in which line the error occurs. The less the readers have to guess, the easier is an answer. Thanks.
This is your first question and you figured out how to format the code correctly. Although this looks like an easy procedure, many counter examples demonstrate, that this is not easy. Because I've moaned so many times about a missing code formatting, let me take the chance to tell you:
Welcome to the forum and thanks for caring about the readability of your question. (I only removed the "if true...end", but who cares)

Sign in to comment.

Answers (1)

Jan
Jan on 10 Apr 2014
Edited: Jan on 10 Apr 2014
Activate the debugger:
dbstop if error
Then run the program again. It stops when the error occurs. Now inspect the local variables either in the command window or the workspace browser and check, where the non-integer or non-positive indices are coming from.
Afterwards a dbclear all deactivates the debugger.
Working with the debugger is a very important programming technique. It is even more efficient than this beloved forum, I have to admit.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!