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

조회 수: 3 (최근 30일)
A
A 2016년 9월 21일
댓글: dpb 2016년 9월 23일
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
dpb
dpb 2016년 9월 23일
The above code should do it...didn't you try it?

댓글을 달려면 로그인하십시오.

추가 답변 (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