Reading through folders getting the warning : ." Index in position 1 exceeds array bounds (must not exceed 1).".
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ammar Alfaili
am 14 Sep. 2019
Kommentiert: Ammar Alfaili
am 16 Sep. 2019
Hello
The answer might be failry easy, but i am kind of stuck in it.
I'm trying to run through multiple subforlders to get a plot which contains data from all these folder. The goal is to compare the results.
But I get the Warning: " Index in position 1 exceeds array bounds (must not exceed 1). " in the second step when reading the files.
D_rough = 'C:\Users\ammar\OneDrive\Dokumenter\Master 2019\waves\Analysis\DATA_WAVE BASIN\Rough';
directories = dir(D_rough,'dir*');
I hope you can help :)
2 Kommentare
Stephen23
am 14 Sep. 2019
Bearbeitet: Stephen23
am 14 Sep. 2019
I would be very surprised if your code works without error, because you call dir with two input arguments:
dir(D_rough,'dir*')
whereas its documentation clearly only shows one input argument is supported. You need something like this:
dir(fullfile(D_rough,'dir*'))
"I get the Warning: " Index in position 1 exceeds array bounds (must not exceed 1). "
That is an error, not a warning.
Akzeptierte Antwort
the cyclist
am 14 Sep. 2019
Bearbeitet: the cyclist
am 14 Sep. 2019
At some point, did you define a variable named dir? MATLAB would then try to access that variable, rather than the command. Clear that variable, and see if it works.
3 Kommentare
Weitere Antworten (1)
Ammar Alfaili
am 14 Sep. 2019
Bearbeitet: Ammar Alfaili
am 14 Sep. 2019
3 Kommentare
Stephen23
am 15 Sep. 2019
Bearbeitet: Stephen23
am 15 Sep. 2019
Your dir usage is very unusual. It is quite possible that none of it works as you expect.
For example:
S = dir(fullfile(D_rough,'dir*'));
N = setdiff({S([S.isdir]).name},{'dir0','dir1','dir2','dir3'});
You exclude the directories dir0, dir1, dir2 and dir3 from N. Is that really the intention? (In my original code that you copied this from, setdiff was used to remove . and ..)
T1 = dir(fullfile(D_rough,N{ii},'dir*')); % improve by specifying the file extension.
C = {T1(~[T1.isdir]).name}; % files in subfolder.
Are your files really named dir... ? That is highly unusual: you have subfolders named dir... and in them are files named dir..., without any file extensions. Possible, but very odd.
You even copied my code comment verbatim: did you follow my advice?
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!