Savraj,
when using the legend function, place your variable names in single quotes, as you would for coding a plot title or for your x or y axis.
the code
legend('Variable1', 'Variable2', 'Variable3');
placed inside your nested for loop should give you your legend.
