I posted this already as a comment in the other thread, but I'll put it here too:
MIMT gifwrite() works to write I/IA/RGB/RGBA and indexed color images from 4D arrays. MIMT gifread() can read the image with minimal hassle.
Pay attention to the synopsis if you intend to read GIF files in versions newer than R2018a -- regardless of what tools you're using. If you're using a newer version, you will not be able to correctly read most multiframe color GIF files unless you make that effort.
Stitching the frames together to generate a colormap is a bad idea, since it means that no frame can have a unique optimized local color table. The more dynamic the color content is over the sequence, the worse the entire image will look.
If you don't use third-party tools like those to do the job, the canonical way to do this with imwrite() is tedious. That's just the way it is. You would have to write a loop and quantize each frame individually if you want good color range. The same goes for reading the file.