Data = readtable('autompg.csv', 'VariableNamingRule','preserve');
Displacement = Data.displacement;
Horsepower = Data.horsepower;
Acceleration = Data.acceleration;
variableNames = {'Displacement', 'Horsepower', 'Weight', 'Acceleration'};
Predictors = [Displacement, Horsepower, Weight, Acceleration];
corr_matrix = corr(Predictors, 'Rows', 'complete');
[S,AX,BigAx,H,HAx] = plotmatrix(Predictors);
xdata = Predictors(:, j);
ydata = Predictors(:, i);
p = polyfit(xdata, ydata, 1);
plot(ax, xdata, polyval(p, xdata), 'r--');
corr_val = corr_matrix(i, j);
text(ax, 0.5, 0.9, sprintf('r = %.3f', corr_val), ...
'Units', 'normalized', 'HorizontalAlignment', 'center', 'FontSize', 8);
AX(i,1).YLabel.String = variableNames{i};
AX(iterations,i).XLabel.String = variableNames{i};