how plot a correct interpolation with surf plot?
14 ビュー (過去 30 日間)
古いコメントを表示
Im using the code:
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
for plotting the contour:
using surf function and using X and Y coordinates for its location, but when a use the same view of the 2D contour it seems to be interpolated wrong, any ideas about what could be my mistake? how could a I get a contour plot for figure 2 as similar than figure 1.
As you see, the yellow values seems to be affected with the other data using surf plot, any idea about how to obtain the interpolation plot as similar as fig 1? Thanks in advance
0 件のコメント
採用された回答
darova
2020 年 3 月 31 日
編集済み: darova
2020 年 3 月 31 日
It happens because of different scales of data. Don't know why MATLAB get confused about it (even linear interpolation)
scale and center your data before interpolation
sc = (max(z)-min(z))/(max(y)-min(y));
y = y - mean(y);
x = x - mean(x);
y = y*sc;
x = x*sc;
yv = linspace(min(y), max(y), 50);
zv = linspace(min(z), max(z), 50);
[Y,Z] = meshgrid(yv, zv);
X = griddata(y,z,x,Y,Z,'cubic');
C = griddata(y,z,c,Y,Z,'cubic');
3 件のコメント
darova
2020 年 3 月 31 日
You can scale them back
sc = (max(z)-min(z))/(max(y)-min(y));
y0 = mean(y);
x0 = mean(x);
y = (y-y0)*sc;
x = (x-x0)*sc;
yv = linspace(min(y), max(y), 50);
zv = linspace(min(z), max(z), 50);
[Y,Z] = meshgrid(yv, zv);
X = griddata(y,z,x,Y,Z,'cubic'); % made a mistake before
C = griddata(y,z,c,Y,Z,'cubic'); % made a mistkae before
Y = Y/sc + y0; % scale back
X = X/sc + x0;
surf(X,Y,Z,'cdata',C) % plot original
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!