MATLAB: How to fix the legend

legend

Hello,
'parnam' contains 8 1×1 structures (data and text). The data contains the latitude, longitude and altitude of a sensor. I want to create a legend for my plot that states the latitude of each plot, but it only prints the first.
figure
for k=1:m
scatter(x(:,k),y(:,k)), hold on
legend(sprintf('aircraft at %2.2f degrees latitude', parnam{1,k}.data(1,1)))
end
hold off

Best Answer

There's only one legend per plot; you're overwriting each pass thru the loop.
for k=1:m
scatter(x(:,k),y(:,k))
if k==1, hold on, end % can't get an "onner"
end
legend(num2str(parnam{1,1:m}.data(1,1)).','aircraft at %2.2f degrees latitude')