error using open, too many input arguments. error in fopen

9 views (last 30 days)
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?

Accepted Answer

dpb
dpb on 25 Aug 2015
"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.
  2 Comments
Pree
Pree on 25 Aug 2015
thank you. I put open only on one of the lines instead of fopen.
Walter Roberson
Walter Roberson on 25 Aug 2015
It helps when you post the actual code, especially the code at the line that is creating the error, together with the complete error message.

Sign in to comment.

More Answers (1)

Hussain Baloch
Hussain Baloch on 7 Dec 2018
open system ('PV50')
nvals = 0;
figure
for gval=0.2:0.2:1
nvals=navals+1;
gvalsStr-num2Str(oval,3);
set_param('PV50/G1','Gain',gvalStr);
sim('PV50');
plot(v,i);
hold on
end
hold off
this is not working pls help urgently

Community Treasure Hunt

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

Start Hunting!