Simply load MNIST dataset in Matlab

Solution for Simply load MNIST dataset in Matlab
is Given Below:

I have tried the procedure given here:

https://www.mathworks.com/help/deeplearning/ug/data-sets-for-deep-learning.html

after downloading the .gz files from http://yann.lecun.com/exdb/mnist/

but it simply does not work, I get the following error:

Number of images in the dataset: 2055376946 ...
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.

Error in processImagesMNIST (line 31)
X = reshape(X,numCols,numRows,numImages);

Error in main (line 10)
XTrain = processImagesMNIST(filenameImagesTrain);

Any ideas? This is very annoying for such a simple dataset. Also it is unfortunate that it is provided in this strange binary format ‘ubyte’. Any other links with a more convenient format for the MNIST original dataset. (But ideally I would like to load it from this ubyte format)

This is something that is supposed to work “out of the box” that s why its particularly annoying; one does not want to code a specific script to read this binary data. Especially for such a well-known dataset.

I found out myself: use the uncompressed files! (without .gz extension) … so Matlab s code is obviously wrong (they feed the compressed .gz files on their example) this is very strange…
i.e. this code is wrong:

oldpath = addpath(fullfile(matlabroot,'examples','nnet','main'));
filenameImagesTrain = 'train-images-idx3-ubyte.gz';
filenameLabelsTrain = 'train-labels-idx1-ubyte.gz';
filenameImagesTest="t10k-images-idx3-ubyte.gz";
filenameLabelsTest="t10k-labels-idx1-ubyte.gz";

XTrain = processImagesMNIST(filenameImagesTrain);
YTrain = processLabelsMNIST(filenameLabelsTrain);
XTest = processImagesMNIST(filenameImagesTest);
YTest = processLabelsMNIST(filenameLabelsTest);

the filenames must instead be those of the uncompressed files