Representing a Matrix Graphically (but not exactly)

Hello All, I'm new here. I tried looking for this topic, but couldn't find anything.
What I want to do is to represent a matrix graphically. That means that I want the values of each cell in the matrix to appear on a graph on the X,Y coordinates of the cell. For instance, if I have the next matrix:
5 2 1
0 2 3
9 3 7
So the 5 in the first row will be at (1,1), 2 at (1,2), 1 at (1,3), etc. The values can be replaced by '*' or any other symbol really.
Thanks, eliya

 채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 3일

0 개 추천

Or if you want a representation that is color coded but contains no symbols
imagesc(ArrayName)

추가 답변 (4개)

Paulo Silva
Paulo Silva 2011년 3월 3일

0 개 추천

a=[5 2 1
0 2 3
9 3 7]
axis([0 size(a,2) 0 size(a,1)])
for b=1:numel(a)
[x,y]=ind2sub(size(a),b)
text(x,y,num2str(a(b)))
end
Matt Fig
Matt Fig 2011년 3월 3일

0 개 추천

Like this (a surface?):
Z = [5 2 1
0 2 3
9 3 7];
surf(Z.')
xlabel('X')
ylabel('Y')
Matt Tearle
Matt Tearle 2011년 3월 3일

0 개 추천

z = [5 2 1 <etc>
[m,n] = size(z);
[x,y] = meshgrid(1:n,1:m);
plot3(x(:),y(:),z(:),'o')
or
text(x(:),y(:),num2str(z(:)))
Or even just
image(z), colorbar
BTW, typically you'd think of the columns as the x coordinate, so 2 would actually be at x=2, y=1. If that's not what you want, just flip the role of x and y.

댓글 수: 1

Or instead of plot3, use scatter3
scatter3(x(:),y(:),z(:))

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

Eliya
Eliya 2011년 3월 3일

0 개 추천

Thanks everyone. It all worked, but Walter's suggestion to use imagesc was the best as I'm writing a "Game of Life" kind of program. Thanks again for the prompt replies!

카테고리

도움말 센터File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by