Combining two surfaces from two files into one surface plot

8 次查看(过去 30 天)
Is there any way to combine two surface plots from diffterent matlab files into one surface plot?
Assuming that the range of X,Y,Z coordinates of the two surfaces are close.

采纳的回答

Dave B
Dave B 2022-4-6
编辑:Dave B 2022-4-6
Do you mean two different .fig files?
You can generally find objects that live in an axes with findobj, which is good for looking for an object of a specific type. You can reparent those objects by setting the Parent (e.g. to a new axes, or from one old axes into another):L
This bit creates a couple of example surfaces
z1=peaks;
z2=z1+randn(size(z1))/5;
figure(1)
surf(z1)
savefig('foo1.fig')
figure(2)
surf(z2,'FaceColor','r')
savefig('foo2.fig')
The bit below opens the figures
f1 = openfig('foo1.fig');
f2 = openfig('foo2.fig');
The final section finds the surfc and copies them into a new axes:
s1 = findobj(f1,'Type','surf');
s2 = findobj(f2,'Type','surf');
figure;
ax=axes; % the new target for the old surfs
copyobj(s1, ax) % or s1.Parent = ax; to move it
copyobj(s2, ax); % or s2.Parent = ax; to move it
% note that the new axes won't inherit the configuration of the old axes
% (e.g. the 3-d view), but see below for an alternative.
view(3)
% or: just do copyobj(s1,s1.Parent) or s2.Parent=s1.Parent if
% you want to copy/move the second surface into the same axes
% as the first, preserving the view and other axes characteristics
  3 个评论
Dave B
Dave B 2022-4-6
if you have two .fig files that contain your figures you can save them wherever you want, just as long as you can find them when it's time to load. If you don't specify the path when loading, MATLAB will look in the search path.
As a general rule, a .fig file is independent of the code used to generate it. The .fig file contains all of the data bout your surfaces and does not re-run the code used to make them.
If you have two .m files which contain code to generate some surface, you can just call them hold on between the calls MATLAB will plot them in the same axes (provided you don't clear the axes or figure).
% Note: no files needed below, simply call hold on between calls to surf
% and MATLAB will overlay the surfaces
z1=peaks;
z2=z1+randn(size(z1))/5;
figure(1)
surf(z1)
hold on
surf(z2,'FaceColor','r')

请先登录,再进行评论。

更多回答(0 个)

类别

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

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by