surf function give wrong graph

조회 수: 12 (최근 30일)
quan ng
quan ng 2022년 2월 20일
편집: DGM 2022년 2월 21일
I am using surf to draw a surface when given 3 matrix, y_test, z_test, m_k.
y_test and z_test is both 1x100. m_k is a 100x100 matrix.
I have attach mat files of y_test, z_test, m_k.
I use this code:
surf(y_test,z_test,m_k)
And it give the graph like in the surf.png i attach.
This graph is wrong though, i try this point :
plot3(0.7990,8.8932,1.7064,'.r','markersize',10);
It is the red point you see in the graph. It is way off, not even close to the surface.
If i use loops to pot this point by point, like the code below:
count_i = 0;
count_j = 0;
for i = y_test
count_i = count_i + 1;
if count_j == 100
count_j = 0;
end
for j = z_test
count_j = count_j + 1;
m_k(count_i,count_j) = - m_k_ranhTQ_1(x,input,beta0,kbeta_bao_hoa,x_delta,kI,Ka,time,Z1,Z2,i,j);
plot3(y_test(count_i),z_test(count_j),m_k(count_i,count_j),'.r','markersize',1);
hold on;
end
end
It will give correct graph, like in the correct plot.png i attach. The redder point i use to check is on the "surface" of points.
Can someone explain this? Is the surf function some how alter the results to get a smooth surface or something?

채택된 답변

Voss
Voss 2022년 2월 20일
Try this instead:
load('m_k.mat');
load('y_test.mat');
load('z_test.mat');
% surf(y_test,z_test,m_k);
surf(y_test,z_test,m_k.');
hold on
plot3(0.7990,8.8932,1.7064,'.r','markersize',10);
It looks like, the way m_k was calculated the first index (rows) corresponds to y_test and 2nd index (columns) corresponds to z_test, but in surf() it has to be the other way around (this is hard to notice when the matrix is square). Observe:
figure
try
surf(1:4,1:10,randn(4,10)) % generates an error
catch ME
disp(ME.message);
end
Data dimensions must agree.
surf(1:4,1:10,randn(10,4)) % works
In surf(), vector X goes along the second dimension of matrix Z, and vector Y goes along the first dimension of Z.
  댓글 수: 4
quan ng
quan ng 2022년 2월 21일
i forgot about it. Accepted!
Voss
Voss 2022년 2월 21일
Thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Computational Geometry에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by