function plot_scatter(params, response, data)
%plot_scatter(params, response, data)
%
%  Description:
%
%    This function will scatter plot the results of a Dakota sampling study
%    with a linear regression.  Use readtabular.m to read the Dakota 
%    tabular results file from the study.
%
%  Inputs:
%
%    params   = a cell vector with the parameter labels
%    response = a cell vector with the response labels
%    data     = an array of parameter/reponse data from the study
%
%  Outputs:
%
%    Scatter plots with linear regression for each parameter/response
%    pairing.
%
%  Contact:
%
%    Bob Cochran
%    Applied CHT
%    rjc@heattransfer.org
%
%  History:
%
%    Who    Date   Version  Note
%    ---  -------- -------  -----------------------------------------------
%    RJC  05/23/17  0.1.0   Initial release.
%
%==========================================================================

nvars = length(params);
nresp = length(response);
pdata = data(:,1:nvars);
rdata = data(:,nvars+1:end);

figure

[H,AX,BigAx,P,PAx] = plotmatrix(pdata,rdata);
title('Input/Response Scatter Plot with Correlations')
for vi = 1:nvars
  for ri = 1:nresp
    subplot(AX(ri,vi));
    x = pdata(:,vi);
    y = rdata(:,ri);
    p = polyfit(x,y,1);
    linreg = polyval(p, x);
    hold on
    plot(x, linreg, '--','LineWidth',2)
    hold off
    axis tight
    if (ri == nresp)
      xlabel(params{vi})
    end
    if (vi == 1)
      ylabel(response{ri})
    end
  end
end
