Legend for multiple data series at once
Ältere Kommentare anzeigen
I am plotting 3 datasets (5x100 elements each) directly from the 5x100x3 matrix (I transposed the matrix to get a 100 points x 5 lines plot):
semilogy(matrix(:,:,1)','b.')
hold on
semilogy(matrix(:,:,2)','r.')
semilogy(matrix(:,:,3)','g.')
legend('Data 1','Data 2','Data 3')
When I add the legend, it only shows the same color for each dataset, as it is considering the first 3 rows of the first dataset:

I tried this:
p1 = semilogy(matrix(:,:,1)','b.');
hold on
p2 = semilogy(matrix(:,:,2)','r.');
p3 = semilogy(matrix(:,:,3)','g.');
legend([p1 p2 p3],{'Data 1','Data 2','Data 3'})
But I got the error:
Error using legend
Specify the data series to include in the legend as a vector of graphics objects.
How to add a legend to each 100x5 set?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Legend finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
