read data formatted like ip address from a text file
5 views (last 30 days)
I want to read a file formatted like this :
218.104.22.168: 222.214.171.124 126.96.36.199 2188.8.131.52
2184.108.40.206: 2220.127.116.11 18.104.22.168
into a matrix like this:
222.214.171.124 2126.96.36.199 188.8.131.52 2184.108.40.206
2220.127.116.11 218.104.22.168 22.214.171.124 0
Elias Gule on 28 Mar 2018
Assuming that you want to store the data as strings, and that the delimiters are 'whitespace' and ':'.
filepath = 'the_path_to_your_file.txt';
str = fileread(filepath);
cstr = cstr(~cellfun('isempty',cstr)); % Remove all empty line data
ips = regexp(cstr,'(\d+\.?)+','match');
This should give you a cell array of cell arrays containing the defined ip's.