Why doesn't importdata recognize space or tab as delimiters?
20 次查看(过去 30 天)
显示 更早的评论
I am working on MATLAB 2015a and trying to process a data matrix which looks like this.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/197490/image.png)
Each number is separated by a tab. However, when I tried to import my data using
data = importdata('myfile.txt');
the result is not a multi-row numerical matrix, but a single-row char matrix. I tried to switch the delimiter to space, but it doesn't work. I even specified the delimiter using
[data, delim] = importdata('myfile.txt', '\t');
or
[data, delim] = importdata('myfile.txt', ' ');
but it still doesn't work and the returned delim is NaN. How can I solve this problem? Thank you!
0 个评论
采纳的回答
madhan ravi
2018-10-10
编辑:madhan ravi
2018-10-10
fid =fopen('myfile.txt','r')
file = textscan(fid,'%f %f %f %f %f %f %f %f %f %f %f \n','Delimiter','','collectoutput',1);
fclose(fid)
cell2mat(file)
or try
a=load('myfile.txt')
data = importdata('myfile.txt') %couldn't regenerate the issue in 2017a
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Database Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!