Jump to content
HenLopes

Open a .txt file scripting

Recommended Posts

Hello,

 

I'm trying to open a .txt file in Compose but I get an error.

Error: invalid input in argument 1; type must be a string or a valid file stream in call to function textscan at line number 2

 

 

fid                         = fopen('nodes.txt');
track                       =textscan(fid, '%f %f %f %f %s %s');
fclose(fid);
track_node                  = track{:,1};
x_node_track                = track{:,2};
y_node_track                = track{:,3};
z_node_track                = track{:,4};

 

Do I need to import the txt file firstly ? If yes how can I do it?

How can I call a .txt file in Compose?

 

Thank you!

Share this post


Link to post
Share on other sites

Hello,

 

Could you please share you text file 'nodes.txt'?

 

Using fopen command is enough to import the file, apparently there is a problem with your text file. That is why it would be good if you could share it here.

 

Regards,

 

Roberta

Share this post


Link to post
Share on other sites

Do you see 'fid' variable has a negative value ?  if so, you might not have the 'nodes.txt' in the current working directory. can you please make sure you have the file in current working directory, if not change the working directory or have the fullpath to the file. 

 

like: 

fid =fopen('C:/temp/test.txt', 'r')

 

thanks,

Manoj kandukuri

HenLopes likes this

Share this post


Link to post
Share on other sites
Quote

Do you see 'fid' variable has a negative value ?  if so, you might not have the 'nodes.txt' in the current working directory. can you please make sure you have the file in current working directory, if not change the working directory or have the fullpath to the file. 

like: 

fid =fopen('C:/temp/test.txt', 'r')

 

Thank you very much Manoj.

I worked that way.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×