MATLAB: How do i randomly show the pictures i have in the array

random pics matlab

this is my code:
folder = 'F:\school\matlab\project\pictures\pictures alone'
filePattern = fullfile(folder, 'apple.jpg','condor.jpg','elephant.jpg',...
'Koala.jpg','orange.jpg','whale.jpg','Penguins.jpg');
i would like to use imshow() to show the pictures but i want it to show random pictures from the filePattern i declared above… can anyone please help me with this?
i am using matlab R2013a

Best Answer

Your usage of fullfile is incorrect. The arguments you pass except for the last should be folder.
There are many ways to do what you want. The gist of it is to store your options in a cell array and choose an element at random with any of the random functions, randi for example. Or just reorder the array with randperm.
folder = 'F:\school\matlab\project\pictures\pictures alone';
files = {'apple.jpg','condor.jpg','elephant.jpg',...
'Koala.jpg','orange.jpg','whale.jpg','Penguins.jpg'};
%pick one at random and show:
imshow(fullfile(folder, files{randi(numel(files))}));
pause(5)
%pick another at random, it may be the same
imshow(fullfile(folder, files{randi(numel(files))}));
%reorder the array randomly:
randomisedfiles = files(randperm(numel(files)));
%etc.