Difficulty setting legend dataset colour

조회 수: 2 (최근 30일)
NA
NA 2020년 6월 29일
댓글: NA 2020년 6월 29일
Hello,
I am having some difficulty with my legend. I keep getting the following error: 'Subset must be a vector of graphics objects.'
My current code is:
figure;
h1 = plot((conTime(1:15,[1:3,5:6,8:end])), conBw(1:15,[1:3,5:6,8:end])); hold on;
h2 = plot((b9Time(1:15,3:end)), b9Bw(1:15,3:end)); hold on;
set(h1, 'Color', 'r');
set(h2, 'Color', 'b');
xlabel('Time (days)', 'FontSize', 12);
ylabel('Body Weight (g)', 'FontSize', 12);
xlim([1,50]);
xticks(0:5:50);
legend([h1, h2], 'Control', 'Intervention', 'location', 'southeast', 'FontSize', 11);
legend box off;
On the other hand, when I set my legend using the following code, both my 'Control' and 'Intervention' appear with red lines, rather than red and blue (as I have set them):
legend('Control', 'Intervention', 'location', 'southeast', 'FontSize', 11);
Your feedback is greatly appreciated.
Many thanks.
  댓글 수: 8
Fangjun Jiang
Fangjun Jiang 2020년 6월 29일
I see. I could duplicate your error now. The result of [h1, h2] could be a vector but can't be a matrix. The error message is poorly constructed.
NA
NA 2020년 6월 29일
Precisely. I'm glad it is sorted now, and will know what to do next time. Thanks again :)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by