Hi,
Instead of inserting of legend function to modify data1" in "error bar" , you can specify the legend labels using the DisplayName property. Set the DisplayName property as a name-value pair when calling the plotting functions
For instance in this situation
instead of
errorbar(Data,y,err','.','color','b');
you can set the DisplayName property inside errorbar like below
errorbar(Data,y,err','.','color','b','DisplayName','Error bar');
and can remove the legend function you have added at the end.
Hence you would be able to eliminate fourth field (Confidence bounds2) and modify the display name
for reference you can check out the below link
hope it helps,
thanks