2016-11-15 46 views
0

我已經嘗試了很多組合來解決這個問題,從論壇等,但每個都不能解決我的問題。我有兩個line地塊和兩個scatter地塊。我只希望在legend中顯示兩個scatter地塊。排除圖例中的實體(散點圖和線) - Matlab

這裏是我的代碼:

line([-4, 4],[0,0], 'LineWidth', 2, 'Color', [0 0 0]); % Do not want this in Legend 
hold on 
line([0, 0],[-4,4], 'LineWidth', 2, 'Color', [0 0 0]); % Do not want this in Legend 
hold on 
i_h = scatter(valence_i, arousal_i,'MarkerEdgeColor', 'k', 'MarkerFaceColor', 'b'); 
legend(i_h, 'Induced Emotion') 
hold on 
p_h = scatter(valence_p, arousal_p, 'MarkerEdgeColor', 'k', 'MarkerFaceColor', 'r'); 
legend(p_h, 'Perceived Emotion') 
axis([-4 4 -4 4]) 
xlabel('Valence') 
ylabel('Arousal') 

的代碼確實排除line對象,但legend最後一次通話覆蓋前一個。 line對象僅僅是在劇情中間標出一個十字,因此它們在legend中不被期望。

回答

1

您只需要一個電話傳說:

legend ([i_h p_h], 'Induced Emotion', 'Perceived Emotion') 
+0

這工作很好,謝謝。 – user1574598