Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
open text file "invalid argument'

Subject: open text file "invalid argument'

From: Ondrej

Date: 23 Mar, 2010 12:55:12

Message: 1 of 3

Hi Guys can you someone help me with the following, it was working for me before but i don't know what is the problem now,... I have a simple script in which i have to open a text file but i'm getting the following error:

Error using ==> textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in ==> spfit_echidna at 123
allstrings = textscan(fid,'%s');

part of the script:
filename=sprintf('%s%d_%d_%s.%s\n','000',runs(ii), peak, fit, 'TXT');
% open file
[fid, message]=fopen(filename,'r');
if fid < 0
% scan file
allstrings = textscan(fid,'%s');
allstrings = allstrings {:};

strangly enough when i just manually copy the file name from "sprintf" and open the file as follows it works properly, :

many thanks,

Subject: open text file "invalid argument'

From: Sadik

Date: 23 Mar, 2010 13:26:05

Message: 2 of 3

Hi Ondrej,

Why do you put an endline character at the end? This one: \n


Subject: open text file "invalid argument'

From: Ondrej

Date: 23 Mar, 2010 20:31:22

Message: 3 of 3

arrr, just because i'm stupid,...
many thanks, that was the problem,...
cheers, ondrej

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us