My code is keep plotting the wrong data

조회 수: 3 (최근 30일)
Peter
Peter 2022년 7월 7일
댓글: Star Strider 2022년 7월 7일
I have a 9 coloumns by 150 rows matrix and I have chosen three coloumns from it to form my new 3 comloumns matrix, so I chose second to be my Z (hight) and 8 and 9 to be my x and y respectively.
M = TEST(:,[8;9;2])
surfl(M)
So, now I have a 3x150 Matrix and idealy it is 3 coloumns where first is X, second is Y and third is Z. Whenever I use surf. comand it plots wrong data and I am sure when I pick a plotted point it is all wrong. I do not know what to do to fix it.
and I do not want to plot a mathematical function I already have X Y and Z, and when I separate them, the code gives me an error that Z must be a matrix not vector, while it is obviously a matrix. I do not know how to solve it.

채택된 답변

Star Strider
Star Strider 2022년 7월 7일
Perhaps —
TEST = randn(150,9);
M = TEST(:,[8 9 2]);
x = M(:,1);
y = M(:,2);
z = M(:,3);
L = size(M,1);
xv = linspace(min(x), max(x), L);
yv = linspace(min(y), max(y), L);
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x,y,z,Xm,Ym);
figure
surf(Xm, Ym, Zm)
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
This should work with your data. It would help to have it to be certain.
.
  댓글 수: 2
Peter
Peter 2022년 7월 7일
It worked Thank you so much :)
Star Strider
Star Strider 2022년 7월 7일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

추가 답변 (1개)

Jonas
Jonas 2022년 7월 7일
may the scatter3() command is suffiecient to visualize your data, you interpolate (e.g. interp3) your XYZ data to generate more points and use surf() after that

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by