I assume it doesn't really crash with an error but it takes close to forever to output that many files...(?)
I don't know about the memory limitations you have .. your database should be around 1.5GB ... but can't you save the results in an matrix or a cell array first? Like
results = zeros(length(database))
result(i) = NumNi;
Maybe you could even do this inplace, so database(i,1) = NumNi to save memory. Alternatively, if you run into memory problems you could divide your loop into smaller chunks and process some 10000 or 100000 elements at a time in parallel, then save and then continue.
If you have a lot of memory you could also try to setup a ramdisk and output your mat files on this disk - which is much faster even compared to an ssd disk.