MATLAB Answers

How to obtain a meshgrid surf plot on the right coordinate location?

조회 수: 5(최근 30일)
I'm trying to use this code for ploting this gridding on its correct location with a 3D perspective.
please be sure your cd is the same location of L10.mat and L10D.mat downloaded files.
load L10.mat; %find it attached
load L10D.mat; %find it attached
plot3(L10(:,2),L10(:,3),L10(:,4),'k','linewidth',1)
hold on
scatter3(L10D(:,2),L10D(:,3),L10D(:,4),'filled','k');
hold on
x = L10D(:,2); y = L10D(:,3); z = L10D(:,4); c = L10D(:,5);
xv = linspace(min(L10D(:,2)), max(L10D(:,2)), 120); yv = linspace(min(L10D(:,3)), max(L10D(:,3)), 120);
[X,Y] = meshgrid(xv, yv); Z = griddata(x,y,z,X,Y); C = griddata(x,y,c,X,Y);
surf(X, Y, Z,'cdata',C);
box on
view(-80,20)
This code is ploting the figure:
But, we easily can check that the rigth gridding surf plot corresponds to the figure:
Note, when I run the code, it appears this error:
Warning: Duplicate data points have been detected and
removed - corresponding values have been averaged.
Warning: Duplicate data points have been detected and
removed - corresponding values have been averaged.
Any ideas what could be my code error for acquiring this figure?

  댓글 수: 0

Sign in to comment.

채택된 답변

darova
darova 14 Mar 2020
You are interpolation in Z direction
Try to interpolate in X
yy = linspace(min(y),max(y),20);
zz = ...
[Y,Z] = meshgrid(yy,zz)
X = griddata(y,z,x,Y,Z);
...

  댓글 수: 6

표시 이전 댓글 수: 3
darova
darova 14 Mar 2020
Or simpler with inpolygon
y10 = L10(:,3);
z10 = L10(:,4);
in = inpolygon(Y,Z,y10(1:end-1),z10(1:end-1));
Z(in) = nan;
Philippe Corner
Philippe Corner 31 Mar 2020
Hi darova, I'm very grateful with your help with this question. I'm having a confusion with other dataset and I though that maybe you could give me your advice..
find attached the data (A_PRE.mat and Aelec.mat) im using now for the same plotting than before.
load A_PRE.mat; %find it attached
load Aelec.mat; %find it attached
figure(1)
X=A_PRE(:,1); Y=A_PRE(:,4); Z=A_PRE(:,5);
[xq,yq]=meshgrid(linspace(min(X),max(X),100),linspace(min(Y),max(Y),100));
zq=griddata(X,Y,Z,xq(:),yq(:),'linear');
[c,h]=contourf(xq,yq,reshape(zq,100,100),'LineStyle','none','LevelStep',100);
hold on
plot(cotas(:,1),cotas(:,2),'k','linewidth',4) %elevation data
hold on
scatter(X,Y,'filled','k')
figure(2)
plot3(Aelec(:,2),Aelec(:,3),Aelec(:,4),'k','linewidth',2);
hold on
scatter3(A_PRE(:,2),A_PRE(:,3),A_PRE(:,4),'filled','k')
hold on
level=A_PRE;
x = level(:,2); y = level(:,3); z = level(:,4); c = level(:,5);
yv = linspace(min(level(:,3)), max(level(:,3)), 100);
zv = linspace(min(level(:,4)), max(level(:,4)), 100);
[Y,Z] = meshgrid(yv, zv);
X = griddata(y,z,x,Y,Z,'cubic');
C = griddata(y,z,c,Y,Z,'cubic');
yA = Aelec(:,3); zA = Aelec(:,4);
in = inpolygon(Y,Z,yA(1:end-1),zA(1:end-1));
Z(in) = nan;
surf(X, Y, Z, 'cdata',C);
shading interp
we obtain from these 2 figures:
Im wondinring why interpolation with surface function seems to be relate with the data on the left, and produce a distorcion on the interpolated data. I'm confused because on the example of my question it didnt have that problem.. Any suggestion about how to make the fig2 look similar than the simple contour of fig1?
Thanks a lot in advance.
Philippe Corner
Philippe Corner 31 Mar 2020
Pleas if you know the answer, share it here:
https://la.mathworks.com/matlabcentral/answers/514368-how-plot-a-correct-interpolation-with-surf-plot

Sign in to comment.

추가 답변(0개)


Translated by