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

 Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 14 Nov. 2020
Bearbeitet: Ameer Hamza am 14 Nov. 2020
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');

2 Kommentare

This did the trick, Thanks!
I am glad to be of help!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by