Error using fopen - Not enough input arguments

12 views (last 30 days)
nicolas mansard
nicolas mansard on 22 Jun 2017
Edited: Jan on 22 Jun 2017
Good morning ,
I'm having a problem with fopen in this piece of code... I get the following message:
Error using fopen. Not enough input arguments.
Thank you.
fprintf('\n ============================================ \n');
promt='enter data file of raw data, e.g. 414NM_data.txt : \n ' ;
%nr=input(promt,'s');
nr = sprintf('%d_cropcrop.txt', name); % <----------------------------------------
files = dir(nr);
fileID = fopen (files.name);
if irig ==1
% LabView file in TOS for Rig1 has 23 header lines. Change if your nr.
% of header lines is different.
C = textscan(fileID, '%.1f %d %d %d %.1f','Headerlines', 23);
fclose(fileID);
t = double(cell2mat(C(1)));
t=t*ticonv;
f = double(cell2mat(C(2)));
p = double(cell2mat(C(3)));
d = double(cell2mat(C(4)));
% For simplification and to allow for a possible later installed DLT
% transducer at Rig1, a DLT variable is defined here as well for Rig1,
% but for now it uses the DC-DT data --> dxin = DLTin for the case of
% Rig1:
DLT = d;
elseif irig==2
% LabView file in TOS for Rig2 has 49 header lines. Change if your nr.
% of headerlines is different.
C = textscan(fileID, '%.1f %d %d %d %.1f','Headerlines', 49);
fclose(fileID);
t = double(cell2mat(C(1)));
t=t*ticonv;
f = double(cell2mat(C(2)));
p = double(cell2mat(C(3)));
d = double(cell2mat(C(4)));
DLT = double(cell2mat(C(5)));
else
fprintf('Rig used is not defined \n')
end
clear fileID z
else end

Answers (1)

Jan
Jan on 22 Jun 2017
Edited: Jan on 22 Jun 2017
If
fileID = fopen (files.name)
shows the error, that it has to few inputs, files.name is empty. This means that dir(nr) did not finf a file, because such a file does not exist in the current folder. Either there is a typo in the name or the wrong folder is currently active. Prefer absolute path names, which include the path.
Such problems can be examined easily using the debugger. Set a breakpoint in the code and step through the program line by line. Then you can check the contents of the variables.

Tags

Community Treasure Hunt

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

Start Hunting!