(Solution) using histc to get 'binIndex', i,e. the bin index of each element in the data array. Bin index indicates in which bin that particular element was put.
[~,binIndex]= histc(XArray,binranges);
varMatrix=zeros(1,numberOfBins); % filled with dummy values
for iterator=1:max(binIndex)
varMatrix(iterator)=var(XArray(find(binIndex==iterator)));
end
%Now the varMatrix will contains the variance for each bin.