Error when using legend on contour plot(2014b

3 次查看(过去 30 天)
When using a script that performs a contour plot I get the following message when trying to add a legend:
Warning: Error updating Legend. Following is the chain of causes of the error:
Index exceeds matrix dimensions.
The script is working fine when using 2014a, so there have been some changes made from 2014a to 2014b that I don't seem to grasp.
Anyone who could fill me in on this particular problem? Cheers!
  1 个评论
Marc Jakobi
Marc Jakobi 2015-6-4
Have you found a solution to this problem yet? I am having the same problem with scatter. My code:
hx = figure;
subplot(211)
h(1) = plot((1:1:8),nanmean(LI_brutto2),'k','LineWidth',2); hold on
for i = 1:size(LI_brutto,1)
h(i+1) = scatter((1:1:8),LI_brutto2(i,:),'r','filled'); hold on %#ok<*SAGROW>
end
h(i+2) = line([4.5 4.5],[0 3500],'Color','k');
L = {'Mittelwert','Spez. Speicherpreis brutto'};
order = [2 1];
legend(h(order),L(order))
There is no problem when trying to access h(1). But as soon as I try to access h(2+) using legend() I get the error message. If I put h(2) or h([2 3 4]) in the workspace, I get a 1xN graphics array (Scatter Scatter Scatter).

请先登录,再进行评论。

回答(1 个)

Marc Jakobi
Marc Jakobi 2015-6-4
Okay, I found the reason for my problem. Maybe it might help you, too. The matrix I was scattering contained NaNs. I removed all the NaNs and now the legend works.

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by