フィルターのクリア

How to create a legend from a cell array?

30 ビュー (過去 30 日間)
Paolo Ottonelli
Paolo Ottonelli 2020 年 1 月 9 日
コメント済み: Adam Danz 2020 年 1 月 9 日
Hi, I have C that is a 3x1 cell array in which there is one number per cell. I have plotted 5 different curves and I would like to use those numbers as a text in a legend for the first 3 curves. I have written the following code but there are my three numbers referred only to the first graph
p=cell2mat(C);
legend(mat2str(p,2),'real data','real data 2' ,'Location','southeast')

採用された回答

Adam Danz
Adam Danz 2020 年 1 月 9 日
How's this work for you?
plot(magic(5))
C = {1;2;3};
p = cellfun(@(x){num2str(x)},C)
legend(p{:},'real data','real data 2' ,'Location','southeast')
200109 113308-Figure 1.png
  2 件のコメント
Paolo Ottonelli
Paolo Ottonelli 2020 年 1 月 9 日
This program works, thank you very much
Adam Danz
Adam Danz 2020 年 1 月 9 日
Glad I could eventually understand what you clearly described :D

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

その他の回答 (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