MATLAB: How to plot all the points on a matrix (in 3d) with the x and y being the locations of the elements of the matrix, and the z being the value of the elements

graph

Hello!
I have a question. I am trying to make a scatter plot in 3d, with a 49 by 49 matrix as a starting value. My end goal would be to have 2401 (49×49) points, with each point being at the x and y value of the row and collum of the respective matrix element, and have the z be the value of the element.
Basically, I want to graph every point in the 2d matrix in 3d without having to separate each point of the matrix out and graph it. If this is not clear, please tell me.
Thank you so much to everyone who replies!
-Kevin

Best Answer

Try this:
M = rand(49); % Original Matrix
[rv,cv] = ndgrid(1:size(M,1), 1:size(M,2)); % Create Index Vectors For ‘M’
figure
scatter3(rv(:), cv(:), M(:)) % 3D Scatter Plot Using ‘scatter3’
.