MATLAB: How to make the location of legend do not interfere the axes

legend

Hi,
Could someone know how to make the location of legend with 'NorthEastOutSide' do not interfere the axes? I mean when I use this option the width of the axes will be changed. So I can't use multiple x axes. Is it possible to make the NorthEastOutSide option doesn't affect the width of the axes?
The below pictures show the axes before and after using the legend.
Before
After
Thank you.

Best Answer

There is an input argument of legend() that lets you specify where you want the legend to appear.