Error on plotting (Index in position 1 exceeds array bounds. Index must not exceed 51.)
2 views (last 30 days)
Show older comments
I want to plot T_n on 3D graph but don't know how. Please help
1 Comment
Accepted Answer
KSSV
on 22 Apr 2022
Simply try:
surf(T_n)
1 Comment
Walter Roberson
on 22 Apr 2022
My reading of the code in the image is that T_n has one too many rows and columns compared to the X and Y grids of coordinates. But that would have been a lot easier to prove if only the actual code had been given, instead of an image of the code...
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)
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots 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!