I have recently changed to a newet version of Matlab (R2019) and when I try to add a legend on my graph I get the following error:
'' Inputs must be the same size or either one can be a scalar.''
The code I am using (which was working and great at the previous Matlab version) is this:
x=rand(1,10);
y=rand(1,10);
zfTail=10;
figure(15); clf; hold on; box on
ph_f = plot(2.*x, 2*y, 'ro-.','LineWidth',2,'Color',[0 0.75 0]);
ph_fb = plot(x, y, 'ro-.','LineWidth',.3,'Color',[0.5 0.75 0]);
ph_ft = plot(3.*x, 3.*y, 'ro-.','LineWidth',1,'Color',[0 0.75 0.5]);
legend([ ph_f, ph_fb, ph_ft], 'Location', 'SouthWest',...
{'Escape time distribution',...
['Power-law fit, z = ' num2str(-zfTail,2)],...
'Initial distribution'
},'FontSize',14)
This is what I get at R2019 version:
And this is what I am getting at an older versio R2017b
where ph_f, ph_fb, ph_ft are primitive 1X1 lines Could someone help me? I was not able to find a solution.
The argument {'Escape time distribution', ['Power-law fit, z = ' num2str(-zfTail,2)], 'Initial distribution'}
should be inserted right after the line objects. The following should work:
hleg = legend([ph_f, ph_fb, ph_ft], {'Escape time distribution', ['Power-law fit, z = ' num2str(-zfTail,2)], 'Initial distribution'});
hleg.FontSize = 14;
hleg.Location = 'southwest';
I am not sure why it is not possible to include the FontSize
and Location
properties of legend
on the same line in R2019a.