Put existing 3D figures on subplot
조회 수: 33 (최근 30일)
이전 댓글 표시
I have a couple figures already existing in my program but want to add them together to a subplot. e.g., put fig 1 and fig 5 on a subplot. I found some code and modified it slightly:
%% Original 3D Plot
[X,Y,Z] = peaks;
plot = surf(X,Y,Z);
%% Copy plot to subplots
f = figure;
s1 = subplot(1,3,1);
s2 = subplot(1,3,2);
s3 = subplot(1,3,3);
copyobj(plot,s1);
copyobj(plot,s2);
copyobj(plot,s3);
%% Set different viewing angle for each subplot
view(s1,0,90); title(s1,'view(0,90)');
view(s2,90,0); title(s2,'view(90,0)');
view(s3,0,0); title(s3,'view(0,0)');
My problem is it loses the third dim and plots everything 2D.
댓글 수: 2
답변 (1개)
Md Modassir Firdaus
2022년 12월 30일
Hi everyone
You can try this code to create single figure having subplots. Here single plot is in subplot becouse it does not saved figure 1. First save the created plot then comment "savefig".
clc;
close all;
clear;
%%
z1=peaks;
z2=z1+randn(size(z1))/5;
figure(1)
surf(z1) %creating first figure
savefig('PeaksFile1.fig') % save the figure once then comment it
%%%%
figure(2)
surf(z2,'FaceColor','r') %creating second figure
savefig('PeaksFile2.fig')% save the figure once then comment it
%% Loading saved above figure
f1=hgload('PeaksFile1.fig');
f2=hgload('PeaksFile2.fig');
%% creating subplot
figure(3)
h(1)=subplot(1,2,1);
view(3)
grid on
h(2)=subplot(1,2,2);
view(3)
grid on
%%
copyobj(allchild(get(f1,'CurrentAxes')),h(1));
copyobj(allchild(get(f2,'CurrentAxes')),h(2));
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!