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

3 Ansichten (letzte 30 Tage)
A
A am 21 Sep. 2016
Kommentiert: dpb am 23 Sep. 2016
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);

Akzeptierte Antwort

dpb
dpb am 21 Sep. 2016
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 Kommentare
A
A am 23 Sep. 2016
Thank you. How can I "evaluate the equation at the existing points and compute the difference" for thousands of data points?
Thanks
dpb
dpb am 23 Sep. 2016
The above code should do it...didn't you try it?

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