How to read and save data from text file with variable number of columns in a Matrix in Matlab

Posted by khan on Stack Overflow See other posts from Stack Overflow or by khan
Published on 2014-08-23T21:52:42Z Indexed on 2014/08/24 4:20 UTC
Read the original article Hit count: 206

Filed under:
|
|

I have a text file with integer values. each row contains information about specific object. But unfortunately each row has different number of column. because of which when i try to use

    file_content = load('txtfile.txt');

it gives me error message that previous number of columns does not match.

i also tried to use fgetl, fscanf, etc function but was unsuccessful. Can anybody give me a piece of code, or help me how to read a txt file and save in matrix in matlab. Three sample rows are given below.

1 1 1 1 1 95 17 54 111 92 17 54 111 92 17 54 111 92 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 54 109 92 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 58 109 96 15 58 109 96 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 58 109 96 15 56 109 94 15 56 109 94 15 58 109 96 15 58 109 96 15 56 109 94 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 17 58 111 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 56 109 94 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94

1 1 1 2 96 185 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 15 56 109 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 54 107 92 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 13 56 107 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 54 109 92 15 54 109 92 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94

1 1 1 3 186 245 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 56 109 94 15 58 109 96 15 58 109 96 15 58 109 96 15 58 109 96 13 58 107 96 13 56 107 94 13 56 107 94 13 58 107 96 13 58 107 96 13 58 107 96 13 58 107 96 13 58 107 96 13 56 107 94 13 58 107 96 13 58 107 96 13 58 107 96 13 58 107 96 13 58 107 96 13 58 107 96 13 58 107 96 13 58 107 96 13 58 107 96 13 58 107 96 13 58 107 96 13 60 107 98 13 58 107 96 13 58 107 96 15 58 109 96 13 58 107 96

As you can see the rows doesn't have equal number of columns. So how can i read and save it in a Matrix. Any help in this regards will be highly appreciated. Thanks

© Stack Overflow or respective owner

Related posts about matlab

Related posts about image-processing