randomly access a file in matlab
1 次查看(过去 30 天)
显示 更早的评论
f = dir( myfolder ); ridx = randi(numel(f)); disp( ['Chosen file is: ' f(ridx).name] );
when I run this code for 5 files in the directory the numel shows me 7 instead of 5 with two files with the names of '.' and '.." how can I ommit these two files??
0 个评论
回答(2 个)
Sabarinathan Vadivelu
2013-8-17
Please specify the type of data you are reading from the current folder in this line.
f = dir(['myfolder\*.jpg']);
or any other formats.
0 个评论
Jan
2013-8-17
"." is the current folder, while ".." is the parent folder. You can exclude them explicitly:
f = dir(myfolder);
name = {f.name};
f(strcmp(name, '.') || strcmp(name, '..')) = [];
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!