Clear Filters
Clear Filters

Adding legend for iteration and if condition graph

10 views (last 30 days)
Good day, I currently having problem in insert the legend to a graph. Basically this is my coding in plotting the graph. I am using the DisplayName but the legend is missing also. Is it any other ways to put the legend into my plot?
title('Graph of behaviour against iteration');
xlabel('iteration t');
ylabel('behaviour value');
if max_euc_dist<0.056
plot(i,dataCopyS5(i,:),'g.','MarkerSize',4,'DisplayName','Normal');hold on
else
plot(i,dataCopyS5(i,:),'m+','MarkerSize',4,'DisplayName','Anomaly');hold on
end
The graph cannot change to scatter plot as the size of dataCopyS5 is 1000x8. Hope that my problem faced can be solved. Thank you.

Answers (1)

jonas
jonas on 26 May 2018
Try this,
title('Graph of behaviour against iteration');
xlabel('iteration t');
ylabel('behaviour value');
if max_euc_dist<0.056
h1=plot(i,dataCopyS5(i,:),'g.','MarkerSize',4);hold on
else
h2=plot(i,dataCopyS5(i,:),'m+','MarkerSize',4);hold on
end
legend([h1 h2],'Normal','Anomaly')

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!