Filter löschen
Filter löschen

randomly access a file in matlab

3 Ansichten (letzte 30 Tage)
jalal Ahmad
jalal Ahmad am 17 Aug. 2013
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??

Antworten (2)

Sabarinathan Vadivelu
Sabarinathan Vadivelu am 17 Aug. 2013
Please specify the type of data you are reading from the current folder in this line.
f = dir(['myfolder\*.jpg']);
or any other formats.

Jan
Jan am 17 Aug. 2013
"." 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, '..')) = [];

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by