MATLAB Answers


Slowing of program when adding legend.

Asked by Isktaine on 4 Oct 2012
I'm plotting 4 functions in one graph and then adding a legend. For some reason adding the legend is really slowing the computation time - are there any things that slow the legend function down? For example I'm plotting vectors (about 20,000 elements) inside cell arrays in a for and if loop - does this sort of set up slow the legend function?
Any insight is appreciated,


Sign in to comment.


1 Answer

Answer by per isakson
on 4 Oct 2012
Edited by per isakson
on 4 Oct 2012

legend is slow, especially if it runs into trouble finding a suitable position. Specify a position and see if that improves the speed, e.g.
legend( ...,'Location', 'NorthEast' )


Show 1 older comment
Sad but true, the legend function is very slow. I only use it at the very end of any code that calls it an I expect to wait.
  • Long ago I made a simple replacement for legend because I found it so slow.
  • You might check with profile too see what is going on.
Thanks, I had no idea it was slow in general - good to know!

Sign in to comment.