Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

how to open this file

2 visualizzazioni (ultimi 30 giorni)
zainab hp
zainab hp il 19 Feb 2016
Chiuso: MATLAB Answer Bot il 20 Ago 2021
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 Commenti
Stephen23
Stephen23 il 19 Feb 2016
Modificato: Stephen23 il 19 Feb 2016
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 il 19 Feb 2016
no don't have . Ok I will repeat it.

Risposte (1)

Stephen23
Stephen23 il 19 Feb 2016
Modificato: Stephen23 il 19 Feb 2016
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 Commento
zainab hp
zainab hp il 19 Feb 2016
Thank you very much .You really help me . Thank you again .

Questa domanda è chiusa.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by