I want my function to add a legend to a plot where the legend has a variable number of items depending on N: e.g. '1', '2', '3' if N=3. The help file tells me I can use a matrix or a cell array: legend(M). But I can't find a way of creating a suitable array without fixing the number of cells. For example,
num2cell(1:N)'
doesn't help because legend() only seems to accept cell arrays containing strings, not numeric values. And int2str() doesn't help because it adds spaces in between the numbers.
Best Answer