2

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: enter image description here

And this is what I am getting at an older versio R2017b enter image description here

where ph_f, ph_fb, ph_ft are primitive 1X1 lines Could someone help me? I was not able to find a solution.

0

1 Answer 1

0

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.

2
  • 1
    I am sorry but I have just tested it and it once again does not seem to work on Matlab R2019a.
    – user11607936
    Commented Jun 24, 2020 at 19:25
  • 1
    Hi @Jokerp , my mistake, I was using R2019b. I found the issue for R2019a and updated my post.
    – juju89
    Commented Jun 24, 2020 at 20:27