Info
此问题已关闭。 请重新打开它进行编辑或回答。
how to open this file
2 次查看(过去 30 天)
显示 更早的评论
Hello .. I need to open file have this information
1|24|M|technician|85711
2|53|F|other|94043
3|23|M|writer|32067
4|24|M|technician|43537
5|33|F|other|15213
6|42|M|executive|98101
7|57|M|administrator|91344
8|36|M|administrator|05201
9|29|M|student|01002
10|53|M|lawyer|90703
how to open this in Matlab .I use dlmread but the format data is failed. please help me
2 个评论
Stephen23
2016-2-19
编辑:Stephen23
2016-2-19
Does your file really have parentheses at the beginning of the first line, and end of the last line?
It would be much simpler if you edit your question and upload the complete file, then we can try it for yourselves. Click the paperclip button, then both Choose file and Attach file buttons.
回答(1 个)
Stephen23
2016-2-19
编辑:Stephen23
2016-2-19
You cannot use dlmread with that file because (as its documentation states quite clearly on the very first line) dlmread reads an "ASCII-delimited file of numeric data into matrix". Does the file have only numeric data? No, it does not. It is amazing how useful it is to read the MATLAB documentation.
fid = fopen('temp.txt','rt');
C = textscan(fid,'%f%f%s%s%f','Delimiter','|');
fclose(fid);
>> C{1} % 1st column
ans =
1
2
3
4
5
6
7
8
9
10
>> C{3} % 3rd column
ans =
'M'
'F'
'M'
'M'
'F'
'M'
'M'
'M'
'M'
'M'
The file I used to test my code is attached here:
1 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!