Surface plot mapping positive instead of negative values

Hello,
I am building a surface plot using all negative values in my Z axis. I've put in my code below along with an image of my result. The positive 600 rise on the end is confusing because none of my data is positive. The x and y coordinates are spacing coordinates. Is there a way that I'm configuring the grid that is making the Z-surface positive?
F = scatteredInterpolant(x,y,Nat);
min_x = min(x);
min_y = min(y);
max_x = max(x);
max_y = max(y);
proj_x = linspace(min_x, max_x, 100);
Proj_y = linspace(min_y,max_y,100);
[PX,PY] = ndgrid(proj_x,Proj_y);
PNat = F(PX,PY);
surf(PX,PY,PNat,'EdgeColor','none')
xlabel("Feet")
ylabel("Feet")
zlabel("(mV)")
title("Voltage Drop")
view([-33 55])
colorbar
If I need more information to explain better, please ask!
Thanks,
Evan

 Accepted Answer

This is probably caused by scatteredInterpolant(). Beyond your data, it needs to do extrapolation, and by default, it uses linear extrapolation, which can cause issues. Try to remove the extrapolated values or use the 'nearest' extrapolation. For example, try this line
F = scatteredInterpolant(x,y,Nat,'linear','none'); % 'linear' is used for interpolation and 'none' is for extrapolation
% or
F = scatteredInterpolant(x,y,Nat,'linear','nearest');

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!