surf function give wrong graph
14 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
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
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Computational Geometry についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

