displaying images in random order using 'imread' function

5 ビュー (過去 30 日間)
BA
BA 2022 年 9 月 21 日
コメント済み: BA 2022 年 9 月 21 日
I'd like to write a program that displays these images I've attached to this post in random order. I know how to use the function imread to display these images, but I'm not sure how to write a program that displays them in a random order.
I think possibly utilizing a loop may help but I can't figure it out.
imread('brain-lateral.png');
imread('download.jpeg');
imread('brainlobesanatomy.jpeg');
imread('download2.jpeg');
Thanks

採用された回答

Karim
Karim 2022 年 9 月 21 日
編集済み: Karim 2022 年 9 月 21 日
one method could be the following:
% number of images
numImg = 4;
% random permutation of the integers 1:numImg
imgIdx = randperm(numImg)
imgIdx = 1×4
3 2 1 4
% loop over all images
for i = 1:numImg
% pick the current random index
currImg = imgIdx(i);
% read an image based on the random index
switch currImg
case 1; imread('https://nl.mathworks.com/matlabcentral/answers/uploaded_files/1131875/brain-lateral.png');
case 2; imread('https://nl.mathworks.com/matlabcentral/answers/uploaded_files/1131880/download.jpeg');
case 3; imread('https://nl.mathworks.com/matlabcentral/answers/uploaded_files/1131890/brainlobesanatomy.jpeg');
case 4; imread('https://nl.mathworks.com/matlabcentral/answers/uploaded_files/1131895/download2.jpeg');
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by