I have a figure with 5 subplots. I declare subplot(2,3,X) which includes 6 subplots. The 6th subplot is empty. I am going to move legend to 6th empty position for all plots.
How is it possible?
if you just want to use standard-matlab, you need the handle of the subplot and then you need its position. Then you set the position of the legend to the position of the subplot. Referring to the docs:
Note You can set the legend location by passing the 4–element position vector to the legend function using the ‘Location' option. To define the position of an existing legend, use the set function to assign the 4–element position vector to the ‘Position' property. You cannot use the Location option with the set function
for example:
subplot(2,3,1), plot(1:10,2:11)
myLegend=legend('text1')
set(myLegend,'Units', 'pixels')
myOldLegendPos=get(myLegend,'Position')
hold on
h=subplot(2,3,6)
set(h,'Units', 'pixels')
myPosition=get(h,'Position')
set(myLegend,'Position',[myPosition(1) myPosition(2) myOldLegendPos(3) myOldLegendPos(4)])
Maybe try legendflex from the File Exchange, it looks like it can do what you want.