I am trying to plot several groups (25 in my example) of data on one plot, with a legend representing each. Here is my code:
aa = 25; c = hsv(n); n = 25 figure; hold on; axis tight; grid on; box on; for k = 1:n; xy = c(k,:); % assign a different color to each group
a = outputs2{1,k} % my data is held in cells in a 1 x 25 cell array
if sum(a) ~= 0; % some groups of data are empty (this data was generated from the nctool
h(k) = scatter(a(:,3), a(:,1), aa, xy, 'filled') % seems to work....
name{k} = ['group ' num2str(k)]; % attempting to make a string array for the legend
end end legend(h, name);
But i get this error:
Error using legend (line 120) Invalid argument. Type 'help legend' for more information. Error in PlotOutputs2 (line 19) legend(h, name); Error in run (line 96) evalin('caller', [script ';']);
The plot works, just not the legend. I've tried a hundred different variations and this is the closest i can get.
Also, and this is a different problem, but i spent some time trying to install the legappend tool this morning with no luck. That was also error prone. With that, i ran the example that comes with it and just got errors. I'm not sure what the mistake I'm making with that is.
Also today I reinstalled MATLAB just in case I had damaged the legend tool somehow.
Any help is greatly appreciated!!!!
Best Answer