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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...