"Not enough input arguments" error when using fullfile

57 visualizaciones (últimos 30 días)
Bradley
Bradley el 4 de Dic. de 2024 a las 16:28
Editada: Stephen23 el 4 de Dic. de 2024 a las 17:40
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
Sandeep Mishra el 4 de Dic. de 2024 a las 16:37
Could you please confirm if you are in the same directory where the code previously worked? Also, what is the output of S1?

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
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.

Stephen23
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')
S1 = 0x1 empty struct array with fields: name folder date bytes isdir datenum
F1 = fullfile(S1.folder,S1.name)
Error using fullfile (line 3)
Not enough input arguments.
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.
Solution
I suspect that what you intended to write was this, with cell arrays as inputs to FULLFILE:
F1 = fullfile({S1.folder},{S1.name})
% ^ ^ ^ ^

Categorías

Más información sobre Filename Construction en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by