Here is a working example code. How do I reduce the size of the legend? And why isn't the set(leg, 'position'...) command not working anymore?
Fig1=figure('units','pixels','position',[0 0 600 600])%,'Visible','off');%figure('Visible','off');
Legend={'x=2$\quad$','x=4$\quad$','x=6$\quad$','x=8$\quad$','$E[L_{Boarding}]$=x, N=25','$E[L_{Boarding}]$=0, N=25-x'};
set(0,'defaultlinelinewidth',1.5);
set(0,'defaulttextfontsize',12);
set(gcf, 'Color', 'w');
x=1:10;
y=rand(4,10);
a=repmat(rand(4,1),1,10);
clrs=[0,1,0.4;0,0.6,0.4;0,0.4,0.6;0,0,0.4];
legendpos=[286,200,250,80];
Mrkrs={'o','s','d','*'};
for j=1:4
h(j)=plot(x,y(j,:),'color',clrs(j,:),'Marker',Mrkrs{j},'MarkerSize',8);
hold on
d(j)=plot(x,a(j,:),'Marker',Mrkrs{j},'color',clrs(j,:),'linestyle','--','MarkerSize',6);
end
dummy1=plot(x(1),y(1),'color','k','linestyle','-','visible','off');
dummy2=plot(x(1),y(1),'color','k','linestyle','--','visible','off');
[leg,icons,plots,legend_text] =legend([h(1),h(2),h(3),h(4),dummy1,dummy2],Legend,'interpreter','latex','fontsize',14);%,'position',[100,100,100,100]);
ypos=[0.875,0.625,0.375,0.125];
xpos=[0.03,0.19];
set(icons(15),'ydata',[ypos(3),ypos(3)]);
set(icons(17),'ydata',[ypos(4),ypos(4)]);
set(icons(5),'position',[0.203,ypos(3),0]);
set(icons(6),'position',[0.203,ypos(4),0]);
for j=1:4
set(icons(5+2*j),'ydata',[ypos(j-2*(j>2)),ypos(j-2*(j>2))]);
set(icons(5+2*j),'xdata',xpos+0.5*(j>2));
set(icons(6+2*j),'ydata',ypos(j-2*(j>2)));
set(icons(6+2*j),'xdata',mean(xpos+0.5*(j>2)));
set(icons(j),'position',[0.203,ypos(j-2*(j>2)),0]+[0.5,0,0]*(j>2))
end
set(leg,'units','pixels');
set(leg,'position',legendpos(i,:))