Combine plot figures without losing legend

1 view (last 30 days)
p2 = 'filename.xlsx'
tiledlayout(2,2);
set(groot,'defaultLineLineWidth',1)
figure(1)
hold on
ex = xlsread(p2,'emission','E2:E37');
ey = xlsread(p2,'emission','C2:C361');
echunks = reshape(ey,[36,10])'
colors = jet(10);
grid on
for i = 1:10
plot(ex,rescale(echunks(i,:)), "color", colors(i,:))
end
title('Emission spectrum of QDs with surfactant')
xlabel('Wavelength /nm ')
ylabel('Emission(Normalized)')
legend('1','2','3','4','5','6','7','8','9','10')
hold off
I don't want to change anything about these figures individually
Just want to export them both in one figure

Accepted Answer

Arif Hoq
Arif Hoq on 19 Feb 2022
Edited: Arif Hoq on 19 Feb 2022
you can use subplot. i dont have your data. here is a demo example.
figure(2)
subplot(2,1,1);
x = linspace(0,10);
y1 = sin(x);
y2 = cos(x);
plot(x,y1,x,y2)
legend('sin(x)','cos(x)')
title('plot of sin(x) & cos(x)')
xlabel('Time')
ylabel('sin(x) & cos(x)')
subplot(2,1,2);
y3 = sin(5*x);
y4 = cos(5*x);
plot(x,y3,x,y4)
legend('sin(5*x)','cos(5*x)')
title('plot of sin(5*x) & cos(5*x)')
xlabel('Time')
ylabel('sin(5*x) & cos(5*x)')
  1 Comment
Arif Hoq
Arif Hoq on 19 Feb 2022
try this for loop. adjust your x and y axes data.
figure(2) ;
for i = 1:10
subplot(2, 1, 1) ;
plot(ex,rescale(echunks(i,:)), "color", colors(i,:))
title('Emission spectrum of QDs with surfactant')
xlabel('Wavelength /nm ')
ylabel('Emission(Normalized)')
legend('1','2','3','4','5','6','7','8','9','10')
end
figure(2) ;
for i = 1:10
subplot(2, 1, 2) ;
plot(ex,rescale(echunks(i,:)), "color", colors(i,:))
title('Absorbtion spectrum of QDs without surfactant')
xlabel('Wavelength /nm ')
ylabel('Absorbance')
legend('1','2','3','4','5','6','7','8','9','10')
end

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!