필터 지우기
필터 지우기

how to plot a matrix on a 3D graph

조회 수: 4 (최근 30일)
krivan
krivan 2011년 6월 10일
댓글: VELMURUGAN K 2020년 6월 4일
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.

채택된 답변

Sean de Wolski
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
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개)

krivan
krivan 2011년 6월 10일
Can you please clarify which is doing what especially in the argument of the reshape and what exactly xx(:) does for example. I am just new to Matlab and couldn't find it in the manual.
Thanks.

krivan
krivan 2011년 6월 20일
Brilliant! Thanks for your help!

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by