# undefined function 'corrplot

89 views (last 30 days)
Alwin on 25 Jun 2012
Commented: Adam Danz on 13 Apr 2021
Hi, I wanted to create a graphical correlation matrix according using the corrplot function ( http://www.mathworks.com/help/toolbox/econ/corrplot.html) but when I try using the function I get the following message:
Undefined function 'corrplot' for input arguments of type 'double'.
I also looked for the function using 'which'- command. And I couldn't find the functiin. Is it possible that my Matlab version (2011b) doesn't have the function? Is it possible to download the function on the Mathworks website?
Thank you.

Adam Danz on 17 May 2020
Edited: Adam Danz on 17 May 2020
FYI, plotmatrix() is quite similar and with just a few additional lines, you can recreate most of the corrplot().
Here's a demo.
% Unlike corrplot, plotmatrix cannot receive a table.
% Form a matrix of variables in each column.
data = [Horsepower, Weight, Acceleration, MPG];
nVars = size(data,2);
% Remove any rows that contain NaN values. Otherwise corr() will
% return NaN.
data(any(isnan(data),2), :) = [];
% Create plotmatrix
figure('Name', 'carsmall_data')
[sh, ax, ~, hh] = plotmatrix(data);
arrayfun(@(h,lab)ylabel(h,lab),ax(:,1), {'Horsepower','Weight','Accel.','MPG'}')
arrayfun(@(h,lab)xlabel(h,lab),ax(end,:), {'Horsepower','Weight','Accel.','MPG'})
% Compute correlation for each scatter plot axis
[r,p] = arrayfun(@(h)corr(h.Children.XData(:),h.Children.YData(:)),ax(~eye(nVars)));
% Label the correlation and p values
arrayfun(@(h,r,p)text(h,min(xlim(h))+range(xlim(h))*.05,max(ylim(h)),...
sprintf('r=%.2f, p=%.3f',r,p),'Horiz','Left','Vert','top','FontSize',8,'Color','r'),...
ax(~eye(nVars)),r,p)
% Change marker appearance
set(sh, 'Marker', 'o','MarkerSize', 2, 'MarkerEdgeColor', ax(1).ColorOrder(1,:))
lsh = arrayfun(@(h)lsline(h),ax(~eye(nVars)));
% Add least square regression line.
set(lsh,'color', 'm')
Adam Danz on 13 Apr 2021
Note: based on conversation with dpb, the correlation coefficient and the slope of the regression line are equal after standardizing the data. For example (comparing Weight and Horsepower)
rho = corr([Weight, Horsepower],'type','pearson','rows','pairwise','tail','both')
rho = 2×2
1.0000 0.8733 0.8733 1.0000
n = isnan(Weight) | isnan(Horsepower);
polyfit(zscore(Weight(~n)),zscore(Horsepower(~n)),1)
ans = 1×2
0.8733 0.0000

owr on 25 Jun 2012
It looks like it was added in 2012A. I dont think there is anywhere to download just one function, too many dependencies, best thing would be to install 2012A if possible.