how can I show all of my data in the legend for each curve?
조회 수: 3 (최근 30일)
이전 댓글 표시
My plot has 10 curves which are according to the data of EC as shown in figure. However the legend displays only the last term in EC, where EC is a row vector as shown. I want to display all the data terms in EC in the legend one by one to exactly express the plotting curves. My syntax for the legend is given by:
EC = [0.0052 0.0078 0.0104 0.0130 0.0156 0.0182 0.0208 0.0234 0.0260 0.0286];
for j = 1:length(EC)
.
.
.
end
lgd=legend(['EC=',num2str(EC(j)),'\m'])
댓글 수: 0
답변 (2개)
Christopher McCausland
2021년 3월 20일
lgd is outside the for loop with no buffer array to hold the data. This is why only the last value is being displayed. While this would work if the position of lgd was changed to inside the for loop any inclusion of a for loop with the plot command makes me a little nervous due to the computational resorces required.
I would suggest trying something like this instead: (note the changes to 'legend')
EC = [0.0052 0.0078 0.0104 0.0130 0.0156 0.0182 0.0208 0.0234 0.0260 0.0286];
legend(['EC=',num2str(EC),'\m']);
There may need to be some additional formatting however that should display everything. Let the forumm know how it goes and if you need any other help with it.
Christopher
댓글 수: 0
darova
2021년 3월 20일
Try this
[x,y] = meshgrid(0:0.1:5,0:5);
y = sin(x)./y;
plot(x',y')
s0 = sprintf('curve #%d,',0:5);
s1 = strsplit(s0,',');
legend(s1{1:end-1})
댓글 수: 3
참고 항목
카테고리
Help Center 및 File Exchange에서 Title에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!