read data formatted like ip address from a text file

8 ビュー (過去 30 日間)
Hessa saad
Hessa saad 2018 年 3 月 28 日
コメント済み: Hessa saad 2018 年 3 月 28 日
I want to read a file formatted like this :
256.13.34.14: 257.13.34.15 221.18.87.18 266.13.77.19
257.13.34.15: 256.13.34.14 221.18.87.18
into a matrix like this:
256.13.34.14 257.13.34.15 221.18.87.18 266.13.77.19
257.13.34.15 256.13.34.14 221.18.87.18 0
  5 件のコメント
Elias Gule
Elias Gule 2018 年 3 月 28 日
do you want to the data in string format or do you want it converted to double? This is very important in that it to a degree dictates the type of storage used for the data.
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 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by