Use imagesc to plot data extracted from hist3
Afficher commentaires plus anciens
Hello, I have two vectors
X = [-1 -5 3 6 -1 7];
Y = [-1 -6 3 6 -1 7];
I want to plot the corresponding number of times each (x,y) couple appears in those vectors on a imagesc plot. For example the couple (-1,-1) appears twice, and all the others only once.
To do so I tried to first use the MATLAB function hist3 to get a 2D histogram of my data:
hist3([X', Y'],[numel(X) numel(Y)]);
This returns the following graph, which looks correct:

But I don't find a 2D histogram very clear and I wanted to use a contour plot to display my data. To use imagesc I did
N = hist3([X', Y'],[numel(X) numel(X)]);
figure
imagesc(X,Y,N);
colorbar
which returns the foolowing graph:

which is absolutely not what I am looking for. The axis are completely out. According to MATLAB documentation, N is "a matrix containing the number of elements of "[X', Y']" that fall in each bin of the grid", it seems to be OK for what I want. Does anybody has an idea on what I am missing here?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Histograms dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!