Use index as coordinates in a 3D scatter plot

2 vues (au cours des 30 derniers jours)
Cerina Gordon
Cerina Gordon le 14 Juil 2017
Commenté : Walter Roberson le 15 Juil 2017
Hi,
I have an n x n x n binary matrix, ex,
A(:,:,1) = [1 0; 0 1]
A(:,:,2) = [1 0;0 0]
I'd like to plot it as a 3D scatter plot with the position of each point determined by the indices of each 1. For example, the previous matrix would yield a scatter plot with points at (1,1,1), (2,2,1) and (1,1,2). What's the most efficient way to do this?
Thanks,

Réponse acceptée

Walter Roberson
Walter Roberson le 14 Juil 2017
[r,c,p] = sub2ind(size(A), find(A));
scatter3(r, c, p)
  2 commentaires
Cerina Gordon
Cerina Gordon le 14 Juil 2017
Thanks for your reply, this didn't work as written but I think you must've meant ind2sub because replacing sub2ind with that worked perfectly
Walter Roberson
Walter Roberson le 15 Juil 2017
Sorry, yes, ind2sub()... Somehow I keep typing the one when I mean the other.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by