Search code examples
matlabmatlab-app-designer

How to list only n first files in folder?


I have about 1500 image files in a folder and listing all using dir() last too long and sometimes crashes the AppDesigner. Is there a way to list only the first or the first n images at a given time?


Solution

  • No, this is not possible, because dir essentially is a wrapper of a operation system function (such as the Windows dir and the Linux 'ls'). So now you have two (actually three but you're not gonna like at least one of them^^) options

    1. it shouldn't cause much trouble to call 1500 files. Have a look if it is really the dir command, which causes trouble. Use the Rund and Time functionality in the Editor
    2. use dir with a pattern. Eg. lst = dir() returns an array of structs with everything in the current folder -- including . and .., which are usually nothing you need. Use lst = dir('*.m') instead to get all .m files. In your case, it can be lst = dir('d_Seite_*.jpg'). I am not sure if that saves you much time but at least memory
    3. restructure how your data (images) is stored so that there are less files available. You could run a background task that moves only the n latest files into the folder latest_files and moves them out again if there are newer ones...