Undefined function 'txt2mat' for input arguments of type 'cell'

Dear friends: I wrote a line of code to read the data from a txt file. My txt file is a combination of the numbers and text. But I received an error of (Undefined function 'txt2mat' for input arguments of type 'cell'). I also attached the txt file. Any help is really appreciated.
clc
clear all
close all
data = txt2mat('cont-0001.txt',0,2,'BadLineString',{')'},'ReadMode','block');

2 commentaires

You forgot to attach the text file.
Oh, no. i do it again.

Connectez-vous pour commenter.

 Réponse acceptée

Star Strider
Star Strider le 13 Août 2016
You have to download the txt2mat function from the File Exchange and put it in your user path (in Windows systems this is C:\Users\~YourUserName~\Documents\MATLAB\). Then you should be able to use it, just as any other function.

7 commentaires

Dear Star Strider: My Matlab is R2012a. I tried to download txt2mat from file exchange but there were no txt2mat download option. can you help further? I am also installing the R2016a.
You have to download and unzip the file. Click on the Download Zip button at the top right of the page, and follow the instructions to download it. I’ve not unzipped files in a while, but (in Windows systems) if you then click on the file in ‘File Explorer’, it will let you unzip the file automatically. Then copy the contents of the unzipped file (that could be one or more files, since I don’t know how txt2mat is written) to somewhere in your MATLAB user path, and you should be able to use it just as you would any other function.
To illustrate:
man, Thank you soo much. this is the second time that you saved me. I really appreciate your help. in fact in the matlab R2015b that i installed, it has an option "add-on". I went through the add on, searched the "txt2mat" then download and add it to the matlab path and now my code is working. Again thank you.
Moreover, the way you explained to me is really helpful for matlab releases that doesn't have add-on option like R2012.
As always, my pleasure!
Thank your for your complimentary comments, too!
masoud meskin
masoud meskin le 14 Août 2016
Modifié(e) : masoud meskin le 14 Août 2016
Sorry to disturb you again. Actually i have 250 txt files and i want to extract the data from them. The name of the txt files are cont-0001,cont-0002, .... . When i run the code for only one txt file, it works. But when i try to run in in a loop, it gives me error :
Error using txt2mat (line 733) no such file or directory
and this is the code i use in the for loop:
data = txt2mat(strcat('cont-',num2str(i,'%u'),'.txt'),0,2,'BadLineString',{')'},'ReadMode','block');
If it worked before and doesn’t now, see what this returns:
Here_I_Am = which('txt2mat.m')
The only other possibility is to re-start MATLAB and see if it works then. (Run the ‘Here_I_Am’ line again first.) It could be a path problem. You may have to re-install ‘txt2mat’ if restarting MATLAB doesn’t work.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by