surf function give wrong graph

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?

 Risposta accettata

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 Commenti

quan ng
quan ng il 21 Feb 2022
thanks a lot, it works! And i thought i have to use the point by point graph if i can't figure out how to use the surf function
Voss
Voss il 21 Feb 2022
I'm glad it's working! If you don't have other questions about this, do you mind marking my answer as 'Accepted'? I appreciate it!
quan ng
quan ng il 21 Feb 2022
i forgot about it. Accepted!
Voss
Voss il 21 Feb 2022
Thank you!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Computational Geometry in Centro assistenza e File Exchange

Tag

Richiesto:

il 20 Feb 2022

Modificato:

DGM
il 21 Feb 2022

Community Treasure Hunt

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

Start Hunting!

Translated by