Plot the numbers of a matrix as points (dots) in a plot
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ang Vas
il 2 Giu 2015
Commentato: Walter Roberson
il 8 Giu 2015
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.
0 Commenti
Risposta accettata
Mike Garrity
il 2 Giu 2015
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 .
3 Commenti
Walter Roberson
il 8 Giu 2015
"A = A - 1" subtracts 1 from every element of A. So the first subtraction would take A to [0 -1 4 6; 2 -1 7 3; 5 3 4 1]. Clearly after a total of 8 iterations you would have [-7 -8 -3 -1; -5 -8 0 -4; -2 -4 -3 -6] and then there would be no entries in A that were positive and the while() would stop.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Pulsed Waveforms in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!