Readtable (file not getting detected in the directory)

Hello All,
I am trying to import files with some weird extension like '.rec1066-5(4244)','.rec1067-5(4244)'.
The extension is taken care of changing it within the code to '.txt'
But some files are getting imported while some files with similar name and same type are NOT getting imported.
the error is:
Error using readtable
Unable to find or open 'C:\Users\ashis\OneDrive\Desktop\WS\a1.txt'. Check the path and filename or file permissions.
Please help me out!! Thanks!!!
I have added the screenshot now!!
I have added two sample files to be imported. Edited the data within due to some reasons!! but the extension is still same!!

4 Comments

Can you attach any examples? It's difficult for anyone to diagnose without specifics.
No you did not. Take 2 files with their original filenames, and zip them up into a zip file. Then attach the zip file with the paperclip icon to your reply.

Sign in to comment.

 Accepted Answer

Do not bother to rename the file. Instead, when you call readtable() give the option 'FileType', 'text'

7 Comments

Already tried that!!! did not work out :-(
Is it saying that it cannot find the file, or is there a different error message, or is it not interpreting the file the way you would like?
Which MATLAB version are you using?
MATLAB R2022b
The error is same:
Unable to find or open
'C:\Users\ashis\OneDrive\Desktop\WS\MATLAB_scripts_Ashish\HP-EDU_000572_eTA.txt'. Check the path and
filename or file permission s.
I said, "Do not bother to rename the file" -- in other words, pass in the original file name complete with the .rec1066-5(4244) extension.
@Walter Roberson Hey it worked!!! Thanks alot.....
Code is :
rehash
data_read = readtable([file_path filename_old],'Filetype','text','PreserveVariableNames',true);
data_read = table2struct(data_read,"ToScalar",true);
But getting some warnings:
Warning: Table variable names that were not valid MATLAB identifiers have been modified. Since table
variable names must be unique, any table variable names that happened to match the new identifiers
also have been modified.
Could you please help?
Like I said These text files are not of a form that can be understood by readtable. It doesn't make sense for fieldnames to have a dot in them, etc.
Opened in Notepad it looks like this:
Datum;Zeit;BO_ROT.Temp1;BO_ROT.Temp2; 64.75; 66.00; 66.25;****; 65.50;****; 67.75; 64.75; 66.25; 67.00; 0.00; 0.00; 0.00; 0.00; 0.00; 0.00; 0.00; 0.00; 0.00; 0.00; 0.00; 0.00; 0.00; 0.00; -0.25; -0.25; -0.80; -19.00; -0.50; -19.00; 0.25; 0.00; 0.25; 0.00; 64.75; 65.20; 66.48; 64.95; 66.25; 67.05; 19.00; 66.00; 19.00; 67.50; 64.75; 66.00; 67.00; 64.75; 65.20; 66.48; 64.70; 66.00; 66.25; 0.00; 65.50; 0.00; 67.75; 64.75; 66.25; 67.00; 1; 250; 10; 0; 80.0000; 80.0000; 256.8579; 443.5673
all in one line.
You'll have to write your own custom reader for them.

Sign in to comment.

More Answers (1)

It is not robust to change the file name or create new files in the script and expect to access it right away in the script.
insert a "rehash" line before read the file. see "doc rehash"

6 Comments

rehash only applies for the case where the new file is a .m file.
'rehash' and 'rehash path' both did not work out!!!
Error using readtable
Unable to find or open
'C:\Users\ashis\OneDrive\Desktop\WS\MATLAB_scripts_Ashish\HP-EDU_000572_eTA.txt'. Check the path and
filename or file permissions.
Again, attach a couple of files with original filenames, zipped up.
These text files are not of a form that can be understood by readtable. You'll have to write your own custom reader for them.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!