Priyanka - when you plot X vs a as
plot(X,a,'r');
remember that X and a are 3x100 matrices and so you are in fact plotting 100 curves each with their own handles. So if you were to do
h = plot(X,a,'r');
h would be a 100x1 array and all 100 curves/lines would be drawn in red. When you call
legend({'plot1','plot2','plot3','plot4'});
plot3 and plot4 correspond to two of the 100 curves drawn in red...which explains your observation.
What does your X and a data correspond to? Could they be reshaped to 1x300 arrays instead?

