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
採用された回答
その他の回答 (4 件)
Paulo Silva
2011 年 3 月 3 日
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
2011 年 3 月 3 日
Like this (a surface?):
Z = [5 2 1
0 2 3
9 3 7];
surf(Z.')
xlabel('X')
ylabel('Y')
Matt Tearle
2011 年 3 月 3 日
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 件のコメント
Walter Roberson
2011 年 3 月 3 日
Or instead of plot3, use scatter3
scatter3(x(:),y(:),z(:))
カテゴリ
ヘルプ センター および File Exchange で Spline Postprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!