Just to make it easier for people to find I have copied the approach listed in the comments which works for versions of Matlab R2018b onwards (I am currently using Matlab 2021a):
The simplest way to do it is to use: -
leg = legend('Plot1','Plot2',...);
leg.ItemTokenSize = [x1,x2];
By default x1=30 and x2=18 so put larger or smaller numbers as x1,x2 to increase or decrease the legend line size.
I can only modulate the length, not the width by using" leg = legend('Plot1','Plot2',...);
leg.ItemTokenSize = [x1,x2];"