Adding legend for iteration and if condition graph

10 次查看(过去 30 天)
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.

回答(1 个)

jonas
jonas 2018-5-26
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')

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by