Trivial, provided you have the image processing toolbox. Take a look at BWLABEL and REGIONPROPS
M = [ 0 0 0 0 0 0
0 1 0 0 0 0
1 1 0 0 0 0
1 1 0 0 0 0
0 0 0 0 0 0
0 0 0 1 1 1
0 0 0 0 1 1
0 0 0 0 0 0]
P = regionprops(bwlabel(M),'boundingbox')
The last two values of the field BoudingBox will give you the height and the width of each connected region.