How to get random image from specific folder in matlab ?

I have set of image in one folder. From that I want to get only one image from this folder. You can get one image by any feature or any logic or non logic..

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 4 de Mayo de 2014
Editada: Azzi Abdelmalek el 4 de Mayo de 2014
d='Yourfolder';
f=dir([d '\*.jpg']);
n=numel(f);
idx=randi(n);
im=imread(f(idx).name);
imshow(im)

2 comentarios

sagar
sagar el 4 de Mayo de 2014
I am using Matlab 2012 and got this type of error.. Thanks for your reply...
Error using randi First input must be a positive scalar integer value IMAX, or two integer values [IMIN IMAX] with IMIN less than or equal to IMAX.
Error in One_image (line 11) idx=randi(n);
Azzi Abdelmalek
Azzi Abdelmalek el 4 de Mayo de 2014
Editada: Azzi Abdelmalek el 4 de Mayo de 2014
This is because your folder is empty, I mean it doesn't contain jpg files

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 4 de Mayo de 2014

Editada:

el 4 de Mayo de 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by