How to present images i random order?

Hi,
I have 10 images and want to present it in random order.
Since there are other images in that folder, I want to specify the pictures which are presented, and then want to show it in random sequence.
How to do it?
Appreciate.

 採用された回答

KSSV
KSSV 2017 年 4 月 3 日
編集済み: KSSV 2017 年 4 月 3 日

0 投票

files = dir('*.jpg') ; % all jp gimages in folder
N = length(files) ; % total files
idx = randperm(N) ; % random order of numbers till N
for i = 1:N % loop for each file
files(idx(i)).name
end

4 件のコメント

M Min
M Min 2017 年 4 月 3 日
I guess, in that way, some other images that are not gonna present would be included. Isn't it?
KSSV
KSSV 2017 年 4 月 3 日
編集済み: KSSV 2017 年 4 月 3 日
It picks all .jpg files....if you want a selected files, make them a cell and run the loop.
files = {'apple' 'ball' 'cat' 'dog' 'egg'} ;
N = length(files) ;
idx = randperm(N) ;
for i = 1:N
files{idx(i)}
end
dbmn
dbmn 2017 年 4 月 3 日
And if you want a random but repeatable sequence you could set the seed for the random number generation before KSSVs script using
rng(1);
This way the sequence is random but you can always reconstruct the exact same sequence using the same seed (in our case 1).
M Min
M Min 2017 年 4 月 3 日
Thanks a lot!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeRead, Write, and Modify Image についてさらに検索

質問済み:

2017 年 4 月 3 日

コメント済み:

2017 年 4 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by