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)
Show older comments
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
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?
Accepted Answer
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
More Answers (0)
See Also
Categories
Find more on Scatter 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!