Plotting multiple matlab figures into a single subplot

1 view (last 30 days)
I used this script to plot 4 matlab figures located in my desktop into a single plot:
Names of the figures: Idc_C1,Idc_C2,Idc_C3 and Idc_C4
clear all;
clc;
c=zeros(4,1);
h=zeros(4,1);
for i=1:4
h(i)=subplot(2,2,i);
end
for k=1:4
% Load saved figures
c(k)=hgload(strcat('C:\Users\kannan\Desktop\PSCAD_Automation_Modell_4T_HBFB\04_Plots\CASE_C1_SEQ_S1\Idc_C',num2str(k)));
% Prepare subplots
figure
% Paste figures on the subplots
copyobj(allchild(get(c(k),'CurrentAxes')),h(k));
end
The problem with the code is that it creates certain duplicated empty figures after the creation of the original subplot.
How should I modify the code to avoid the generation of the empty matlab figures.
Any sugestions or assistance would be very helpful.
problem.png

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 20 Jan 2020
Edited: KALYAN ACHARJYA on 20 Jan 2020
Remove figure statement within the loop.
clear all;
clc;
c=zeros(4,1);
h=zeros(4,1);
for i=1:4
h(i)=subplot(2,2,i);
end
for k=1:4
c(k)=hgload(strcat('C:\Users\kannan\Desktop\PSCAD_Automation_Modell_4T_HBFB\04_Plots\CASE_C1_SEQ_S1\Idc_C',num2str(k)));
copyobj(allchild(get(c(k),'CurrentAxes')),h(k));
end

More Answers (0)

Community Treasure Hunt

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

Start Hunting!