🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Open a .txt file scripting

User: "HenLopes"
Altair Community Member
Updated by HenLopes

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!

Find more posts tagged with

Sort by:
1 - 3 of 31
    User: "robertavarela"
    New Altair Community Member
    Updated by robertavarela

    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

    User: "manoj kandukuri"
    Altair Employee
    Updated by manoj kandukuri

    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

    User: "HenLopes"
    Altair Community Member
    OP
    Updated by HenLopes

    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.