How do I 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?

4 views (last 30 days)
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 (49x49) 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
  2 Comments
KSSV
KSSV on 25 Jul 2020
As the matrix is 3D...may be (x,y) for each matrix will be same....so, you can plot one matrix as one layer at once....or manually assign some z value as height and plot all at once....am I right?
Kevin Shen
Kevin Shen on 25 Jul 2020
Edited: Kevin Shen on 25 Jul 2020
The matrix is 2d, I just want to make a 3d scatter plot from the 2d matrix, with the x pos of the dot being the row, the y pos being the collum, and the z being the value inside the element of the matrix

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 25 Jul 2020
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’
.
  4 Comments
Kevin Shen
Kevin Shen on 25 Jul 2020
Ah, I see, thanks so much! I was just a bit confused on the random part, but that was just to create the matrix. Thanks for explaining everything so nicely!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!