How to randomly extract 50 images from a file?

3 ビュー (過去 30 日間)
AK
AK 2021 年 3 月 11 日
コメント済み: Jan 2021 年 3 月 11 日
Hello!
I am new to Matlab, so please bear with me. I have a file containing thousands of images. I am trying to randomly select 50 images and save it into a new file.
This is the code im trying to use.
Dest = '/Users/Desktop/Image Dataset';
FileList = '/Users/Downloads/ILSVRC2012_img_val';
Index = randperm(50, numel(FileList));
for k = 1:50
Source = FileList(Index(k)).name;
copyfile(Source, Dest);
end
But I keep getting error "Dot indexing is not supported for variables of this type". How do i fix this?
Thank you!

採用された回答

Jan
Jan 2021 年 3 月 11 日
編集済み: Jan 2021 年 3 月 11 日
Dest = '/Users/Desktop/Image Dataset';
FileList = dir('/Users/Downloads/ILSVRC2012_img_val/*.jpg'); % DIR command was missing
% and perhaps
% the pattern
Index = randperm(numel(FileList), 50); % Swap order of arguments
for k = 1:50
Source = FileList(Index(k)).name;
copyfile(Source, Dest);
end
  2 件のコメント
AK
AK 2021 年 3 月 11 日
Thank you! this helped.
I made the changes you suggested. However, now i recieve the error " error using copyfile. arguement must be text scalar"
Do you know what i could be doing wrong here? Thanks!
Jan
Jan 2021 年 3 月 11 日
Use the debugger to find out, what the variable is. Type this in the command window:
dbstop if error
Then run the code. When Matlab stops at the error, check the arguments of COPYFILE:
class(Source)
size(Source)
class(Dest)
size(Dest)

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by