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

8 次查看(过去 30 天)
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
figure(1)
surf(xvalue,yvalue,zvalue);
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
figure(2)
surf(X, Y, Z1);
%Both surfaceA and surfaceB graphed together
figure(3)
surf(xvalue,yvalue,zvalue);
hold on
surf(X, Y, Z1);
hold off
%%%Attempting to graph surfaceC%%%
%figure(4)
%surf(X,Y,zvalue-Z1);
%or
%surf(xvalue,yvalue,zvalue-Z1);

采纳的回答

dpb
dpb 2016-9-21
Simple.
dZ=zvalue-Test(xvalue,yvalue);
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.
  2 个评论
A
A 2016-9-23
Thank you. How can I "evaluate the equation at the existing points and compute the difference" for thousands of data points?
Thanks

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by