How to make corrplot from Econometrics Toolbox 2x faster?
Latest activity Reply by Jan Studnicka
on 26 Jan 2024
Quick answer: Add set(hS,'Color',[0 0.4470 0.7410]) to code line 329 (R2023b).
Explanation: Function corrplot uses functions plotmatrix and lsline. In lsline get(hh(k),'Color') is called in for cycle for each line and scatter object in axes. Inside the corrplot it is also called for all axes, which is slow. However, when you first set the color to any given value, internal optimization makes it much faster. I chose [0 0.4470 0.7410], because it is a default color for plotmatrix and corrplot and this setting doesn't change a behavior of corrplot.
Suggestion for a better solution: Add the line of code set(hS,'Color',[0 0.4470 0.7410]) to the function plotmatrix. This will make not only corrplot faster, but also any other possible combinations of plotmatrix and get functions called like this:
h = plotmatrix(A);
% set(h,'Color',[0 0.4470 0.7410])
for k = 1:length(h(:))
get(h(k),'Color');
end
3 Comments
tic
A = rand(10);
figure
[h,ax] = plotmatrix(A);
% compare elapsed times of code with commented and uncommented line:
% set(h,'Color',[0 0.4470 0.7410])
for i = 1:length(A)
for j = 1:length(A)
if i~=j
lsline(ax(i,j));
end
end
end
toc