Error on plotting (Index in position 1 exceeds array bounds. Index must not exceed 51.)
1 view (last 30 days)
More Answers (1)
Walter Roberson on 22 Apr 2022
Edited: Walter Roberson on 22 Apr 2022
You use [X,Y] = meshgrid(1:1:n+1, 1:1:m+1) . When you do that, the values in X are 1 through n+1 and the values in Y are 1 through m+1 . You use those values in the surf() call to index T_n(X,Y) . So we need to know: does T_n have at least n+1 rows, and at least m+1 columns ?
Look back at how T_n is assigned to. You assign to T_n(m,n) right near the end of the loop. That implies that T_n has at least m rows and n columns. But notice that those are reversed from your meshgrid construction: your meshgrid is creating a first index based upon n, and a second index based upon m, but your T_n(m,n) is using a first index based upon m and a second index based upon n.
Notice that in the surf() call, you are using a variable named X as the first index of T_n . That would tend to imply that you believe that X corresponds to rows of an array. But that is not the case: in MATLAB, X corresponds to columns (X is horizontal direction, column number is horizontal direction) and Y corresponds to rows (Y is vertical direction, row number is vertical direction.)
If you do need to index in the surf() call, you should perhaps be using T_n(Y,X) . But more likely you should use T_n(1:m, 1:n)