MATLAB: Plot the numbers of a matrix as points (dots) in a plot

gridMATLABmatrixplot

I want to plot the numbers of a matrix as points (dots) in a plot. For example if I have matrix A:
1 0 5 7
3 0 8 4
6 4 5 2
How can I plot it as a whole by having each number of the matrix as a point in the plot?
I mean:
in the position i,j=1,1 where is the number 1 give me 1 dot in the plot at position i,j=1,3 where is number 5 give me 5 dots in the plot at position i,j=3,2 where is number 4 give me 4 dots in the plot and so on. What I want to do is when I have a matrix let’s say 4X3 or 5X8 or in general mXn then I want to create a mXn grid by plot there, any element of the matrix with points. For instance if I have A=[1 2 3 4;5 6 7 8;0 2 3 23] (a 4X3 matrix) how can I create a 4X3 grid in a plot which any number of the matrix appearing in the plot with dots, as an example at the position i,j=1,1 which is the number one in the matrix I want to have 1 dot in the grid ,in the position i,j=3,4 where is the number 23 ,I want to see 23 dots in the grid.

Best Answer

Here's a really simple, but inelegant solution:
A=[1 0 5 7; 3 0 8 4; 6 4 5 2]
cla
axis ij
hold on
while any(A(:) > 0)
[r,c] = find(A>0);
offx = randn/10;
offy = randn/10;
scatter(c+offx,r+offy,'filled')
A = A-1;
end
The inelegant part is that it doesn't do a good job of laying out the dots relative to each other. I'll leave that as an exercise for the reader, as they say. The problem is that a nice layout depends on the number of dots, so it's hard to do a good job while processing all of the dots together. My personal favorite layout would be Brent Yorgey's factorization diagrams .