How can I put in legend all cells from one cell array ?
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (3 件)
Jan
2018 年 2 月 21 日
編集済み: Jan
2018 年 2 月 21 日
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 件のコメント
Walter Roberson
2018 年 2 月 21 日
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 件のコメント
Martinppp
2018 年 2 月 21 日
1 件のコメント
Walter Roberson
2018 年 2 月 21 日
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.
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!