updated the matlab plotting function with legends