I can't parse the actual request, sorry...perhaps give an example of what output you expect as well would help. Is it you're trying to simply process Z skipping over the empty cells or is it adequate to reduce Z by removing empty cells entirely?
As for the error,
Z{i}(cellfun(@isempty,Z{i})) = [];
??? Error using ==> cellfun Input #2 expected to be a cell array, was double instead.
The problem here is you dereferenced Z(i) by using the curlies {} so the result of Z{} is the array not the cell.