How do i subtract or sum two 3D plot in matlab?

26 次查看(过去 30 天)
How i do Sum or Subtract two or more 3D surface plot which is plotted from meshgrid data?

回答(1 个)

Srivardhan
Srivardhan 2023-6-8
Hi mahdi,
As per my understanding, you would like to add or subtract 3D surface plots which is plotted from meshgrid data, assuming meshgrid data is the data from “meshgrid” function.
You can add or subtract the surface plots only when 2D or 3D grid which returns from “meshgrid” function should have equal size for both surface plots.
Here is the code for adding and subtracting 3D surface plots, you can check:
% First surface plot
[X1,Y1] = meshgrid(-10:0.1:10);
plot(X1,Y1);
%sample function 1
Z1 = sin(X1) + cos(Y1);
subplot(2,2,1);
surf(X1,Y1,Z1);
title('Surface plot 1');
% second surface plot.
[X2,Y2] = meshgrid(-10:0.1:10);
%sameple function 2
Z2 = sin(X2) + sin(Y2);
subplot(2,2,2);
surf(X2,Y2,Z2);
title('Surface plot 2');
% addition of surfaces
Z_sum = Z1 + Z2;
subplot(2,2,3);
surf(X1,Y1,Z_sum);
%plotting the function over 2D grid
title('Surface plot 1 + 2');
% Subtraction of surfaces
Z_diff = Z1 - Z2;
subplot(2,2,4);
%plotting the function over 2D grid
surf(X1,Y1,Z_diff);
title('Surface plot 1 - 2');
For further reference, please check the following link to know more about “meshgrid” and “surf” function.
I hope this resolves the issue you were facing.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by