"Not enough input arguments" error when using fullfile
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Im trying to pull a couple different csv files from a folder on my computer. the code im using is directly copy and pasted from other code I have written and have never run into this issue, when I run the code I get the following error:
Error using fullfile (line 3)
Not enough input arguments.
Error in A20241203 (line 8)
F1 = fullfile(S1.folder,S1.name);
Heres the code I wrote to access and the folder and files I need to open. Its three csv files all with (7) in the name.
P = 'my directory';
S1 = dir(fullfile(P,'*(7)*.csv'));
F1 = fullfile(S1.folder,S1.name);
M1 = readmatrix(F1);
Again, ive never run into this issue before, when reading the documentation I dont see how I dont have enough input arguments? Thanks!
1 Kommentar
Sandeep Mishra
am 4 Dez. 2024
Hi @Bradley
Could you please confirm if you are in the same directory where the code previously worked? Also, what is the output of S1?
Antworten (2)
Walter Roberson
am 4 Dez. 2024
S1 = dir(fullfile(P,'*(7)*.csv'));
That is returning the empty result, because it cannot find the directory or cannot match *(7)*.csv files in that directory.
0 Kommentare
Stephen23
am 4 Dez. 2024
Bearbeitet: Stephen23
am 4 Dez. 2024
"I dont see how I dont have enough input arguments? "
Very easily, when S1 is empty:
S1 = dir('thisNameDoesNot*Exist')
F1 = fullfile(S1.folder,S1.name)
Because your code is then exactly equivalent to calling this:
F1 = fullfile()
which clearly does not have any input arguments, thus the error.
Your usage of FULLFILE would also be incorrect when S1 has multiple elements.
In fact, the only time your code would work properly is when S1 is scalar. Which is unlikely to be useful.
Explanation of why this happens: https://www.mathworks.com/matlabcentral/discussions/tips/847976-tutorial-comma-separated-lists-and-how-to-use-them
Solution
I suspect that what you intended to write was this, with cell arrays as inputs to FULLFILE:
F1 = fullfile({S1.folder},{S1.name})
% ^ ^ ^ ^
0 Kommentare
Siehe auch
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!