Error while using function readtable()
显示 更早的评论
I use function readtable to read a txt file, it works well before, but suddenly it don't works anymore and return the error:
>> a2=readtable('dyw_e_u.txt');
Error using readtable
inputs must be a string array, character vector, or cell array of character vectors.
>> a2=readtable("dyw_e_u.txt");
Error using readtable
inputs must be a string array, character vector, or cell array of character vectors.
I think what I input 'dyw_e_u.txt' is a character vector, I don't understand why it return the error, please help, thanks
My text file is like this:
Lat Lon mm.dd.yyyy hh:mm:ss U(m^2/s) V(m^2/s) u(cm/s) v(cm/s) Depth(m)
22.4189 114.9908 2021/5/31 0:00:00 -1.123 1.949 -4.16 7.22 26.993
22.4189 114.9908 2021/5/31 1:00:00 -0.452 1.484 -1.675 5.497 26.993
22.4189 114.9908 2021/5/31 2:00:00 0.361 1.06 1.338 3.926 26.993
22.4189 114.9908 2021/5/31 3:00:00 0.994 0.838 3.684 3.104 26.993
22.4189 114.9908 2021/5/31 4:00:00 1.353 0.544 5.014 2.017 26.993
22.4189 114.9908 2021/5/31 5:00:00 1.597 -0.203 5.917 -0.754 26.993
22.4189 114.9908 2021/5/31 6:00:00 1.916 -1.429 7.097 -5.293 26.993
22.4189 114.9908 2021/5/31 7:00:00 2.289 -2.645 8.482 -9.798 26.993
22.4189 114.9908 2021/5/31 8:00:00 2.466 -3.196 9.137 -11.84 26.993
9 个评论
Dyuman Joshi
2023-10-11
PLease attach the data file.
Zhenyu Huang
2023-10-11
It's working here.
unzip('dyw_e_u.zip')
mat = readtable('dyw_e_u.txt')
What is the output when you run this snippet of code in your MATLAB?
which readtable -all
Mathieu NOE
2023-10-11
I have no issue on my side (R2020b)
unzip dyw_e_u.zip
delete dyw_e_u.zip
a2=readtable('dyw_e_u.txt');
head(a2)
As the others have shown, it's not a syntax issue; more than likely as @Dyuman Joshi was poking at you've aliased the readtable function accidentally.
Besides his suggestion to see what which returns, simply enter
clear readtable
at the command line and try again. That should fix it; if it doesn't, you may have somehow manged to corrupt the install, but that would be highly unlikely--not impossible, but not probable.
Zhenyu Huang
2023-10-12
编辑:Zhenyu Huang
2023-10-12
"if it is in the path the readtable function can't work. But there are no functions or scrips name readtable in this folder. I put it here if anybody have interest to figure out why. " <== that is not true. I took a file and moved it out of the current folder and into a different folder that is still in the search path. It found it and read it in.
Nonetheless we recommend that you not depend on the data folder being in the search path and for you to construct the full path (folder + base file name + extension) using the fullfile function. That way it will definitely find it.
help fullfile
Walter Roberson
2023-10-12
I suggest you use
dbstop if error
and run your code, and then when it stops at the error line, start working backwards to trace the cause.
Ayush Gupta
2023-10-12
I am also not facing any issue in R2022b as well as R2023a.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!