I was a bit busy today but finally had a chance to actually run the MatLab script you supplied. You need to make sure that cell types and cell indices are written as integer binary arrays (not floats). This updated script works as expected:
writevtkscript.m (1.9 KB)