Clear Filters
Clear Filters

How to subtract a surface equation from a surface 'scatter plot'?

4 views (last 30 days)
Hi guys,
I have a somewhat complex question. Simply stated, I have two surfaces, and I want to create a third surface by subtracting one of the two surfaces with the other one. So I want to subtract surfaceA from surfaceB to come up with surfaceC.
But the issue is that surfaceA was created from actual data points, and surfaceB was created from an equation.
How do I create surfaceC given that surfaceA and surfaceB were created differently and are of different type?
Please see my sample code and evaluate my attempt. What do I need to do differently?
Thank you!
%Creating surfaceA from datapoints
Xval = [1 2 3 1 2 3 1 2 3];
Yval = [3 1 2 3 1 2 3 1 2];
Zval = [4 10 5 3 4 6 4 3 2];
xvalue = reshape(Xval,3,3)';
yvalue = reshape(Yval,3,3)';
zvalue = reshape(Zval,3,3)';
%surfaceA graphed
hold off
%Creating surfaceB from equation
x = [1:.5:3];
y = [1:.5:3];
Test = @(x,y)x+y;
[X,Y] = meshgrid(x,y);
Z1 = Test(X,Y);
%surfaceB graphed
surf(X, Y, Z1);
%Both surfaceA and surfaceB graphed together
hold on
surf(X, Y, Z1);
hold off
%%%Attempting to graph surfaceC%%%

Accepted Answer

dpb on 21 Sep 2016
Just evaluate the equation at the existing points and compute the difference.
Or, you could use interp2 to interpolate the original to the same mesh as you used to create the first calculated function. The examples for interp2 illustrate that use, iirc.
A on 23 Sep 2016
Thank you. How can I "evaluate the equation at the existing points and compute the difference" for thousands of data points?

Sign in to comment.

More Answers (0)


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!