Search code examples
filematlabrandom-access

Randomly accessing a file from a folder using Matlab


I am trying to randomly access a file from a folder using matlab. Could you suggest how to go about it? I am planning to use randn function, but i don't understand how.


Solution

  • I think you need a random number with uniform distribution, not normal. So here you go ..

    Files = dir('MyFolder');
    N = size(Files,1) - 2;
    rand = randi(N,1);
    Random_filename = Files(rand+2,1).name;