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 件のコメント

Image Analyst
Image Analyst 2016 年 8 月 13 日
You forgot to attach the text file.
masoud meskin
masoud meskin 2016 年 8 月 14 日
Oh, no. i do it again.

サインインしてコメントする。

 採用された回答

Star Strider
Star Strider 2016 年 8 月 13 日

1 投票

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 件のコメント

masoud meskin
masoud meskin 2016 年 8 月 14 日
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.
Star Strider
Star Strider 2016 年 8 月 14 日
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:
masoud meskin
masoud meskin 2016 年 8 月 14 日
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.
masoud meskin
masoud meskin 2016 年 8 月 14 日
Moreover, the way you explained to me is really helpful for matlab releases that doesn't have add-on option like R2012.
Star Strider
Star Strider 2016 年 8 月 14 日
As always, my pleasure!
Thank your for your complimentary comments, too!
masoud meskin
masoud meskin 2016 年 8 月 14 日
編集済み: masoud meskin 2016 年 8 月 14 日
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');
Star Strider
Star Strider 2016 年 8 月 14 日
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.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by