Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

how to open this file

1 Ansicht (letzte 30 Tage)
zainab hp
zainab hp am 19 Feb. 2016
Geschlossen: MATLAB Answer Bot am 20 Aug. 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 Kommentare
Stephen23
Stephen23 am 19 Feb. 2016
Bearbeitet: Stephen23 am 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 am 19 Feb. 2016
no don't have . Ok I will repeat it.

Antworten (1)

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

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by