How can I put in legend all cells from one cell array ?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have a 20x1 cell array:
g=
'1:54.593'
'1:58.820'
'1:55.448'
'1:55.785'
'1:56.270'
'1:55.259'
'1:58.936'
'1:55.204'
'1:55.479'
'1:56.305'
'1:56.736'
'1:55.781'
'1:57.219'
'1:55.797'
'1:59.418'
'1:53.254'
'1:55.199'
'1:58.210'
'1:54.657'
'1:52.684'
I would like to have this array in legend of one graph with all times in column like it is now. I tried to put:
str = strcat(g(:,1));
legend (str{:})
But it says there is too many input strings so it put in legend just the first time.
I also tried:
legend (g(:,1))
But it's showing the last time on the last cell.
Do you have a solution for this problem ?
Thank you,
Martin
0 commentaires
Réponses (3)
Jan
le 21 Fév 2018
Modifié(e) : Jan
le 21 Fév 2018
Do you mean:
legend(g)
? But for a {20 x 1} cell, this should be the same as g(:,1). Therefore I do not understand, what "it's showing the last time on the last cell" means. Please post some code, which produces the input and the legend command you used. A screenshot of what you get as output might be useful also.
0 commentaires
Walter Roberson
le 21 Fév 2018
You only have one graphic object in your axes. You can only put in one legend entry. You could strjoin(g, char(10)) to create a single string with newlines in it, but you will find that you need to use a custom Position option to make the area big enough as the default would be only one line high because it knows that you are passing in only one object.
If you are thinking that you are plotting multiple objects but MATLAB only knows it as one object then you are probably using a scatter plot or a bar plot with only one group.
You should consider whether it really makes sense to legend multiple times for a single graphics object. If you are using a scatter plot with different colors corresponding to different groups, then one legend per color would make sense from an information perspective, but the way to handle that situation is to use gscatter() which creates one graphic object per group.
0 commentaires
Martinppp
le 21 Fév 2018
1 commentaire
Walter Roberson
le 21 Fév 2018
For a bar graph I don't think it makes sense to legend multiple entries unless you set the CData property to control the color of the individual bars.
Voir également
Catégories
En savoir plus sur Legend dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!