"Not enough input arguments" error when using fullfile
57 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Bradley
el 4 de Dic. de 2024 a las 16:28
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 comentario
Sandeep Mishra
el 4 de Dic. de 2024 a las 16:37
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?
Respuestas (2)
Walter Roberson
el 4 de Dic. de 2024 a las 17:23
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 comentarios
Stephen23
el 4 de Dic. de 2024 a las 17:39
Editada: Stephen23
el 4 de Dic. de 2024 a las 17:40
"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 comentarios
Ver también
Categorías
Más información sobre Filename Construction en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!