"Not enough input arguments" error when using fullfile

6 ビュー (過去 30 日間)
Bradley
Bradley 2024 年 12 月 4 日
編集済み: Stephen23 2024 年 12 月 4 日
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 日
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 日
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 日
編集済み: Stephen23 2024 年 12 月 4 日
"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 Center および File ExchangeFile Operations についてさらに検索

タグ

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by