legend causes thousands of function calls
1 view (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Walter Roberson
on 18 Oct 2013
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 Comments
Jos (10584)
on 19 Oct 2013
Using
legend(handles, CellArrayofStrings)
might be faster than
legend(handles, String1, String2, ...)
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!