how to plot a matrix on a 3D graph
3 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a 6x6 matrix that I need to plot on an 3D graph. The elements 1-2-3-4-5 of the first column should be on the x axis, the elements 1-2-3-4-5 of the first row should be on the y axis, element 0,0 is NaN.
The remaining 5x5 array contains the values for the z axis.
Can somebody please help me how to plot it.
Thanks.
0 个评论
采纳的回答
Sean de Wolski
2011-6-10
[xx yy] = meshgrid(M(1,2:end),M(2:end,1));
plot3(xx(:),yy(:),reshape(M(2:end,2:end),[],1));
or surf or mesh whatever type of plot you want.
Addendum The best way to learn is to do it yourself and break down every line to see what's happening.
%Sample script to identify every op.
M = magic(6)
[xx yy] = meshgrid(M(1,2:end),M(2:end,1))
disp('M(2:end,2:end) = ');
M(2:end,2:end)
disp('M reshaped to column vector: ')
reshape(M(2:end,2:end),[],1)
M =
35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
xx =
1 6 26 19 24
1 6 26 19 24
1 6 26 19 24
1 6 26 19 24
1 6 26 19 24
yy =
3 3 3 3 3
31 31 31 31 31
8 8 8 8 8
30 30 30 30 30
4 4 4 4 4
M(2:end,2:end) =
ans =
32 7 21 23 25
9 2 22 27 20
28 33 17 10 15
5 34 12 14 16
36 29 13 18 11
M reshaped to column vector:
ans =
32
9
28
5
36
7
2
33
34
29
21
22
17
12
13
23
27
10
14
18
25
20
15
16
11
The xx(:) operation does the same thing as reshape in this use of reshape.
1 个评论
VELMURUGAN K
2020-6-4
Hi,
I have a 15x15 matrix that I need to plot on an 3D grid or surface graph. The elements 1-15 of the first column should be on the x axis, the elements 1-15 of the first row should be on the y axis, element 0,0 is NaN.
The remaining 14x14 array contains the values for the z axis.
Can somebody please help me how to plot it.
give the exmaple plot also
Thanks.
更多回答(2 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!