Question

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.

Was it helpful?

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top