- 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?
조회 수: 15 (최근 30일)
이전 댓글 표시
How i do Sum or Subtract two or more 3D surface plot which is plotted from meshgrid data?
댓글 수: 0
답변 (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);
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!