legend causes thousands of function calls

1 次查看(过去 30 天)
I have a simple matlab script wich loads a log file (MAT-file) of roughly 270Mb and then plots the data in some plots. It takes a while to process the data but after roughly 2min its done. However, if I want to add a legend to the plots the script takes over 90min to execute. Using 'profile' I see that the script causes over 1 million function calls to
scribe/private/get_legendable_children
scribe/private/islegendable
ismethod
cell.strmatch
strmacht
Does anybody know this problem? I don't do any fancy stuff. I only load and plot a Mat file.
Thank you for any ideas!

采纳的回答

Walter Roberson
Walter Roberson 2013-10-18
How are you calling legend? Are you just passing in the legend strings? If so then MATLAB needs to visit every object (such as lines) that are legend'able in order to determine whether they have custom legends, need to have a legend entry, or so on.
If that is what you are doing, then when you call legend(), pass in the explicit list of object handles that you are generating legends for, so that it does not need to visit the other objects.
  2 个评论
xlr8t
xlr8t 2013-10-19
Hi Walter,
thank you for your answer. Indeed, I was just passing strings to legend(). I now changed it from
plot(t,y1);
hold on;
plot(t,y2)
legend('entry1','entry2');
to
p1 = plot(t,y1);
hold on;
p2 = plot(t,y2)
legend([p1;p2],'entry1','entry2');
It really seems that this was the key problem. The execution time is now down to 6min. Now it seems, that the legend coloring takes a big portion of the execution time. Don't know if that can be improved as well.
Thanks
Jos (10584)
Jos (10584) 2013-10-19
Using
legend(handles, CellArrayofStrings)
might be faster than
legend(handles, String1, String2, ...)

请先登录,再进行评论。

更多回答(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