Import data from text sheet to a variable
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have an text file with following entries
id pid sigma temp value dist
12 369 1740 528 187 9.01
19 741 730 519 206 9.1
13 405 1003 467 158 10.10
32 2179 419 445 191 11.1
18 721 397 657 120 13.2
22 1478 365 600 304 13.3
41 2520 1180 526 179 13.41
i only want to import the dist value to a variable
i.e i want to have my variable
x = [9.01 9.1 10.10 11.1 13.2 13.3 13.41]
Is there a way I could only the 6th column entries from text file to matlab variable x.
0 Kommentare
Antworten (1)
Azzi Abdelmalek
am 25 Jul. 2015
Bearbeitet: Azzi Abdelmalek
am 25 Jul. 2015
fid = fopen('file.txt')
data = textscan(fid, '%*s %*s %*s %*s %*s %f %*[^\n]','HeaderLines',1);
fid = fclose(fid);
5 Kommentare
Walter Roberson
am 26 Jul. 2015
Navya, unfortunately dlmread() cannot be used for files which contain any text at all, even if the row and columns requested are after where the text is.
dlmread() uses an undocumented feature of textscan() that only works when the columns are purely numeric.
In the cases that dlmread() does work for, it is a matter of the code reading and converting the values first, and then throwing away the parts that are not wanted. As I describe above, it is not possible to read only the desired column, that everything must be read for text files, but the other parts can be discarded.
Siehe auch
Kategorien
Mehr zu Text Data Preparation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!