Following my previous article on the undocumented behavior of the scatter function, one of my readers, Benoit Charles, reported a discovery that in many circumstances the line function generates identical plots much faster than scatter.
Unlike scatter, line does not enable specific data-point marker customization, although the colors could be modified. On the other hand, line only uses a single handle object, saving memory and system resources compared to scatter keeping a separate handle for each data point. So, if you just need to quickly plot a bunch of scattered points then line could be a better choice than scatter.
Here is a simple code snippet, which generates identical plots and shows the performance difference:
>> x=rand(1000,1); y=rand(1000,1); >> tic, for idx=1:100, cla; h=scatter(x,y); end; toc Elapsed time is 2.521322 seconds. >> props = {'LineStyle','none','Marker','o','MarkerEdge','b','MarkerSize',6}; >> tic, for idx=1:100, cla; h=line([x,x],[y,y],props{:}); end; toc Elapsed time is 0.333369 seconds.
In the past, I have posted about other undocumented performance aspects, comparing the documented ismember function with the undocumented ismembc and about cellfun’s undocumented options. If you are aware of other similar functions having identical outputs and a significant performance difference, please let me know.

