Representing a Matrix Graphically (but not exactly)
Show older comments
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
Accepted Answer
More Answers (4)
Paulo Silva
on 3 Mar 2011
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
on 3 Mar 2011
Like this (a surface?):
Z = [5 2 1
0 2 3
9 3 7];
surf(Z.')
xlabel('X')
ylabel('Y')
Matt Tearle
on 3 Mar 2011
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 Comment
Walter Roberson
on 3 Mar 2011
Or instead of plot3, use scatter3
scatter3(x(:),y(:),z(:))
Eliya
on 3 Mar 2011
0 votes
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!