"Not enough input arguments" error when using fullfile

조회 수: 57 (최근 30일)
Bradley
Bradley 2024년 12월 4일 16:28
편집: Stephen23 2024년 12월 4일 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
Sandeep Mishra
Sandeep Mishra 2024년 12월 4일 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?

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2024년 12월 4일 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 2024년 12월 4일 17:39
편집: Stephen23 2024년 12월 4일 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})
% ^ ^ ^ ^

카테고리

Help CenterFile Exchange에서 Filename Construction에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by