필터 지우기
필터 지우기

Put existing 3D figures on subplot

조회 수: 39 (최근 30일)
John Willis
John Willis 2022년 3월 9일
답변: Md Modassir Firdaus 2022년 12월 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
Walter Roberson
Walter Roberson 2022년 3월 9일
view(ax1,3); title(ax1,'view(0,90)');
John Willis
John Willis 2022년 3월 9일
Thanks! worked great.

댓글을 달려면 로그인하십시오.

답변 (1개)

Md Modassir Firdaus
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));

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by