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

조회 수: 4 (최근 30일)
Ang Vas
Ang Vas 2015년 6월 2일
댓글: Walter Roberson 2015년 6월 8일
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.

채택된 답변

Mike Garrity
Mike Garrity 2015년 6월 2일
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
Ang Vas
Ang Vas 2015년 6월 8일
편집: Walter Roberson 2015년 6월 8일
It was all most what i was looking for. The problem that I have with this, is that I can't take the x,y coordinates of each point. I thought that it might be xcoordinates=c+offx and ycoordinates=r+offy and I tried to convert the code in order to have the coordinates like
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')
xcoordinates=c+offx
ycoordinates=r+offy
xy=[xcoordinates;ycoordinates]
A = A-1;
end
but I don't get what I was looking for. I expect to took 45 pairs of numbers (xcoordinates,ycoordinates) as is the numbers of the dots from the matrix A but I unfortunately I din't. Any Ideas !!!
Walter Roberson
Walter Roberson 2015년 6월 8일
"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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Exploration and Visualization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by