read data formatted like ip address from a text file

조회 수: 3(최근 30일)
I want to read a file formatted like this :
into a matrix like this: 0
  댓글 수: 5
Hessa saad
Hessa saad 2018년 3월 28일
no, I want the whole IP to be stored in the matrix, and yes it will be a string array since I can not store the IP as double.

댓글을 달려면 로그인하십시오.

채택된 답변

Elias Gule
Elias Gule 2018년 3월 28일
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= splitlines(str);
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.

추가 답변(0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by