MATLAB: Trouble with glmfit using binomial distribution and logit

glmfitlogistic regressionStatistics and Machine Learning Toolbox

I'm trying to perform logistic regression on a dataset using glmfit. Here is my code:
N = ones(size(feature));
initcoeff = glmfit(feature(:, 1:(w-1)), [feature(:, w) N], ...
'binomial', 'link', 'logit');
w is the width of feature. feature is an array in which each row is an example, and each column is a feature of that example. The last column is a binary vector with the labels for each example as 0 or 1.
When I use 'binomial' as the distribution, I get the following error:
??? Error using ==> glmfit at 171
Y must be a two column matrix or a vector for the binomial distribution.
Error in ==> comptrain at 28
initcoeff = glmfit(feature(:, 1:(w-1)), [feature(:, w) N], 'binomial', 'link',
'logit');
I'm not sure what to do, because Y (feature(:, w)) is a vector. Using other distributions instead of binomial yields an array index mismatch error from somewhere within glmfit.
Any help would be appreciated. Thanks!

Best Answer

The error message is because you have
N = ones(size(feature));
so it is of the size of the whole feature array. You just want
N = ones(size(feature,1),1);
But even easier is to omit N altogether. The default is N=1.