![200109 113308-Figure 1.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260973/200109%20113308-Figure%201.png)
How to create a legend from a cell array?
30 次查看(过去 30 天)
显示 更早的评论
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')
0 个评论
采纳的回答
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/260973/200109%20113308-Figure%201.png)
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Legend 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!