MATLAB: Read textfile seperated by ‘:’ and put it in a table

read text file table

Hi,
I have some data which i would like to use in Matlab. the following file is an example:
% test.txt
!Drawing Name: 1234567 Drawing File: 1234567_0
%Section 1: Header info
1234567:00:19/10/2015::::AB::::CD::::KL
%Section 2: data
1:2:3:4:5:6:7:8::::::::::::::::::::::::::900
%End of File Marker
I want to place this data into a table which makes a new column if ':' and makes a new row if 'CR LF' (enter). The data can always change in length, so section 1 can have 10 delimiters(':') and section 2 can have for example 30 delimiters(':'),
Can someone point me in the right direction or give me some example code? I've tried some functions, but without succes. So far the only function working for me is:
% code
h = fileread('test.txt');
Thanks in advance.
Regards,
pdefesche

Best Answer

Use strsplit() with the delimiter ':'. It doesn't care how many colons are in a row. All the data will be put into a cell array of strings, so you'll need to modify the data type using str2double() if you want to use it for calculations.