I'm performing linear regression analyses (y=xb, solving for b with a given [nx1] vector y and [nxm] matrix x) on a pretty large set of data, using the regstats() function the Matlab statistics toolbox and looping through a series of matrix/vector pairs. The problem is that regstats returns NaN if there are columns of all zeros, because it can't perform the regression. There are columns of zeros in all of my x-matrices, but they do not always appear in the same column numbers. Since each column in my x-matrices represents a real-world variable, I can't just simply remove columns of zeros and run the regression. I need to remove the zeros, remember which columns have been removed, run the regression, and then incorporate 0 values into the b vector result in the appropriate places. That way all of my results represent the same number of variables in the same order, with zeros in the places where that particular variable was not included in the regression. I did this manually with a small set of test data, but now I need to run it for about 800 regression pairs so I need some way to automate searching for and replacing the zero columns.