Effacer les filtres
Effacer les filtres

Put existing 3D figures on subplot

39 vues (au cours des 30 derniers jours)
John Willis
John Willis le 9 Mar 2022
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 commentaires
Walter Roberson
Walter Roberson le 9 Mar 2022
view(ax1,3); title(ax1,'view(0,90)');
John Willis
John Willis le 9 Mar 2022
Thanks! worked great.

Connectez-vous pour commenter.

Réponses (1)

Md Modassir Firdaus
Md Modassir Firdaus le 30 Déc 2022
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));

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by