How to convert text file with different delimiters into a matrix
Show older comments
|Hi,
My text file contains 60K lines with format:| | |
0 qid:10 1:0.000000 2:0.000201 3:0.10090 4:0.0043000 5:0.1900000.. 46:0.650000 #docid = GX000-00-000000
Now I have to load data from this file onto a matrix with column '1' and column '3' to column '48' values ignoring value before colon.
O/P: [0 0.000000 0.000201 0.10090 0.0043000 0.1900000...0.650000] //this is single row in matrix
I tried this:
fid = fopen('Querylevelnorm.txt');
--for loop for each line begins here
tline = fgetl(fid)
C=strsplit(tline)
vector = [];
--for loop for each value in line starting from C(1) then C(3) to C(48)
D=strsplit(char(C(3)),':')
vector=[vector D(2)] ##formulating of vector
--end for
--adding present vector to matrix ## formulating of matrix
--end for
i.e., I am reading each line and first splitting with space and then with colon to get each value. But I am not getting how to populate all these values into a vector and then adding each vector to a matrix. I am new to this matlab programming. Sorry for any wrong editing. Please help me out.
Accepted Answer
More Answers (0)
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!