MATLAB: Error using open, too many input arguments. error in fopen

error using openfopentoo many input arguments

I have a m.file which looks something like this.
for p = 1:2
if p==1
[data,txt,raw]=xlsread('subject_1.xlsx');%%this is reading file of subject 1
fid4=fopen('new_1_datafile.dat','w');
end
if p==2
[data,txt,raw]=xlsread('subject_2.xlsx'); %%%%%%reading file of subject 2
fid4=fopen('new_2_datafile.dat','w')'
end
...
...
%%%written fid1,fid2,fid3 datafiles
...
...
...
%%%there are lots of lines where i calculate different things for each subjects (there are 72 different %%%subjects but for simplicity i am just trying with 2).
fprint(fid4,.......) %%%printing out some important data
fclose(fid1)
fclose(fid2)
fclose(fid3)
fclose(fid4)
end
how can i make sure the fid4 file for the first subject is cleared before writing fid4 file for the second subject? With the above code, I am getting an error message which says, 'error using open, too many input arguments'. The error shows in line 8 when opening fid4 for second subject. So I think it is because I am opening the same file again for the second subject which has been already written for the first subject. But I have allocated different datafile name for the fid4 files for the 2 subjects. Why am I getting this error?

Best Answer

"error using open, too many input arguments'." clearly is bogus as an error message for fopen.
Note above it says "open" not "fopen" which means likely means there's actually a call to function open which indeed does only accept a single argument and the actual line you executed wasn't the one in the code above but something like--
fid4=open('new_2_datafile.dat','w');
NB. also above you've got a conjugate transpose operator at the end of the statement instead of a semicolon--that won't hurt anything from an operational standpoint; just echo the value and return the complex conjugate of a positive integer which is the same as the integer. I don't know what that might do in lastest releases wherein a file handle is an object instead of just a double...
Anyway, make sure you really have fopen everywhere and try again...if it fails again, post the whole error in context with the calling routine, but I'll bet you've got a typo in the m-file you executed.