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

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

回答(1 个)

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);
%sample function 1
Z1 = sin(X1) + cos(Y1);
title('Surface plot 1');
% second surface plot.
[X2,Y2] = meshgrid(-10:0.1:10);
%sameple function 2
Z2 = sin(X2) + sin(Y2);
title('Surface plot 2');
% addition of surfaces
Z_sum = Z1 + Z2;
%plotting the function over 2D grid
title('Surface plot 1 + 2');
% Subtraction of surfaces
Z_diff = Z1 - Z2;
%plotting the function over 2D grid
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