Force a legend entry even if there are no matching elements in the plot
Show older comments
Hi,
I'm generating a plot based on a condition as follows:
d1 = plot(find(Vec == 1), Y(Vec == 1), 'r*', 'DisplayName', 'Data 1');
hold on;
d2 = plot(find(Vec == 2), Y(Vec == 2), 'b*', 'DisplayName', 'Data 2');
d3 = plot(find(Vec== 3), Y(Vec == 3), 'k*', 'DisplayName', 'Data 3');
legend([d1 d2 d3]);
Sometimes the array 'Vec' does not have entries matching the value 3. So there are no points generated with a black marker (k*) and the legend will not show 'Data 3'.
But I still want to force the legend entry to display that the Black points(if any) associate with DisplayName 'Data 3'. How do I achieve this?
Accepted Answer
More Answers (0)
Categories
Find more on Legend in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!