- https://in.mathworks.com/help/matlab/ref/meshgrid.html
- https://in.mathworks.com/help/matlab/ref/surf.html
How do i subtract or sum two 3D plot in matlab?
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
How i do Sum or Subtract two or more 3D surface plot which is plotted from meshgrid data?
0 Commenti
Risposte (1)
Srivardhan
il 8 Giu 2023
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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!