MATLAB: How to create a legend and include loop variable values in the labels while plotting a Matrix

iterating legend numberslegend for a matrix in a looplegend in a loop

u = 1:2:10;
z_x = 1:10;
temp = [1:10;11:20;21:30;31:40;41:50];
figure,
hold on
for l= 1:length(u)
str = ['S = ',num2str(u(l))];
plot(temp,z_x,'DisplayName',str);
end
legend show
The above code displays one value of S multiple times. Since i'm plotting a matrix and want to produce a legend for each uniques curve only one. What correction should I make so that the each S value is displayed only once in the legend.

Best Answer

m = rand(10,8);
plot(m)
legend(compose('s = %d', 1 : size(m,2)))