I have a text file, but unfortunately its been poorly formatted, however i want to read the content of the text file into a a matrix, but I don't know how to do that.
When try to use fscanf
, textscan
, textread
and the rest it just copies everything into one cell, but i don't want it that way.
This how the content looks like: so i want to read only the decimals not the absolute figures. Can someone help me.
1 : 13.27 ; 3 : 20.68 ; 6 : 8.271 ; 7 : 3.308 ; 8 : 8.328 ;
9 : 6.655 ; 10 : 16.58 ; 11 : 9.925 ; 12 : 12.41 ; 13 : 4.135 ;
14 : 9.925 ; 15 : 11.58 ; 16 : 10.87 ; 17 : 1.654 ; 18 : 4.962 ;
19 : 6.655 ; 22 : 10.98 ; 23 : 24.25 ; 24 : 47.33 ; 25 : 11.6 ;
26 : 9.925 ; 27 : 5.809 ; 28 : 5.001 ; 29 : 6.617 ; 30 : 7.577 ;
31 : 9.155 ; 32 : 7.444 ; 33 : 28.58 ; 34 : 9.155 ; 35 : 35.83 ;
I assume that the colon (:) seperates values in a row and the semicolon (;) is separating rows. With this assumption the following function should read your data into a MATLAB matrix
You can than use the functions round, floor, ceil to extract the 'decimal values'.
Just using textscan and ignoring the things you don't need, like the numbers and : gives you quite a simple solution:
Change test.txt to your filename. data is a cell with your doubles in it.
conceptually:
take the string.
Change : and ; with spaces and \n (return) with ;
Assign the string to a variable, the variable should become a matrix.
With a dual loop change the value of each elemnt with
Here you are (If I didn't misunderstood you).