Legend and for loops
조회 수: 5 (최근 30일)
이전 댓글 표시
Hey, I am trying to evaluate some data and show it in a graph consisting of 3 sets each containg Mean values, x-errorbars and a fit function (See picture). But I am only able to get a part of the legend showing the right color for the last itteration or I get the whole legend but the color of my 'mean values' is set to that of the last itteration (symbol is ok). I tried numerus approaches but nothing seems to work. My latest try is this code ():
for (3 times itteration)...... other stuff goin on.....
[h,hh]= errorbar_x_one(eval_complete(2,:),eval_complete(1,:),eval_complete(3,:)); %errorbar_x_one outputs handle of errorbar and handle of scatter
y_loudness_function = loudness_function(x_achse,eval_line_point);%loudness function fit
hhh = plot(x_achse,y_loudness_function,[col_sym.col{col_sym.xxx} ':']);
grid on
col_sym.xxx = col_sym.xxx+1;
h.DisplayName = 'Errorbar';
hh.DisplayName = ['Mean ' condition{col_sym.xxx}] ;
hhh.DisplayName = 'fit';
end
legend([h hh hhh],'Location','NW')
Any help would be greatly appreciated.
댓글 수: 0
답변 (1개)
Mike Garrity
2016년 2월 17일
You're saying you call
legend([h hh hhh], ...)
each time around the loop? That means that each time you're telling legend to forget about the items from the previous iteration and focus on these 3 new objects.
You'll want to move legend out of the loop. You could do something like this:
g = gobjects(1,9);
for i=1:3
[h, hh] = errorbar_x_one( ...
hhh = plot( ...
g(end+1) = h;
g(end+1) = hh;
g(end+1) = hhh;
end
legend(g)
But if you're really putting everything into the legend, then you don't need to give it the handles. So you may be able to do something as simple as this:
for i=1:3
[h, hh] = errorbar_x_one( ...
hhh = plot( ...
end
legend show
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!