Info

此问题已关闭。 请重新打开它进行编辑或回答。

how to open this file

2 次查看(过去 30 天)
zainab hp
zainab hp 2016-2-19
关闭: MATLAB Answer Bot 2021-8-20
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
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.
zainab hp
zainab hp 2016-2-19
no don't have . Ok I will repeat it.

回答(1 个)

Stephen23
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.
You can use textscan to read that file:
fid = fopen('temp.txt','rt');
C = textscan(fid,'%f%f%s%s%f','Delimiter','|');
fclose(fid);
reads the file into one cell array C. You can access each column by indexing into C:
>> 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 个评论
zainab hp
zainab hp 2016-2-19
Thank you very much .You really help me . Thank you again .

此问题已关闭。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by