How to Add Legend to Plotted Data

2 ビュー (過去 30 日間)
mr mo
mr mo 2017 年 12 月 7 日
コメント済み: mr mo 2017 年 12 月 10 日
for i=1:size(b,1)
plotcube([1 1 1],b(i,1:3),1,[1 0 0]);
end
for i=1:size(c,1)
plotcube([1 1 1],c(i,1:3),1,[0 1 0]);
end
for i=1:size(d,1)
plotcube([1 1 1],d(i,1:3),1,[0 0 1]);
end
and the b,c and d matrices are shown below:
b =[2 2 3
3 2 3
4 2 3
2 3 3
3 3 3
4 3 3
2 4 3
3 4 3
4 4 3];
c =[2 2 4
3 2 4
4 2 4
2 3 4
3 3 4
4 3 4
2 4 4
3 4 4
4 4 4];
d =[2 2 5
3 2 5
4 2 5
2 3 5
3 3 5
4 3 5
2 4 5
3 4 5
4 4 5];
At the end I want to add legend to the plotted cubes based on their colors. How can I do that? Thanks a lot.
  3 件のコメント
mr mo
mr mo 2017 年 12 月 7 日
I've asked but he's not answering.
mr mo
mr mo 2017 年 12 月 9 日
編集済み: mr mo 2017 年 12 月 9 日
@Jan Simon: Do you have any idea how to add legend to this function? Thanks a lot.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2017 年 12 月 10 日
Use something like
LineColors = [...] %n by 3 rgb list
ncolor = size(LineColors, 1);
for k=1:ncolor
Lh(k) = line(nan, nan, 'color', LineColors(k, :)) ;
end
legend(Lh, {'first label', 'second label'... })
  1 件のコメント
mr mo
mr mo 2017 年 12 月 10 日
Thanks a lot.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by