The Functions you have defined is working like first readig the list of files in a folder then extracting from files from that folder one by one?
The other solution I was thinking In on main root directory I have 7 folder (7 classes). Each folder have 100 images. So reading each images folder by folder and putting it in one 4D array… 256x256x11x700 or seven different arrays

import glob
DATASET_PATH = ‘D:/Dataset/Multi-resolution_data/Visual/High/’  # the dataset file or root folder path.
files = [f for f in glob.glob(DATASET_PATH + “**/*.mat”, recursive= True)]
for f in files:
print(files[1])