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!