how to make table of ip address numbers

1 回表示 (過去 30 日間)
Jay Hanuman
Jay Hanuman 2016 年 11 月 27 日
コメント済み: Jay Hanuman 2016 年 11 月 27 日
I attached ip address data file. I want to make table of ip address numbers. i.e. suppose I have ip addresses
10.0.12.4
10.0.12.5
10.0.7.4
10.0.8.5
10.0.8.4
then it should be in table format with 4 columns
10 0 12 4
10 0 2 5
10 0 7 4
10 0 8 5
10 0 8 4
how to do this.

採用された回答

Guillaume
Guillaume 2016 年 11 月 27 日
編集済み: Guillaume 2016 年 11 月 27 日
If using R2016b, you can use the new string type. It is then trivial to split the strings in one go with split and then convert to numbers with double:
numericip = double(split(string(X), '.'))
Otherwise, you can use the old-fashioned strsplit + str2double wrapped in a cellfun to create a vector per ip string. You have to use the 'UniformOutput', false option to store these vectors in a cell array, and then convert the whole cell array back to a matrix with cell2mat.
numericip = cell2mat(cellfun(@(ip) str2double(strsplit(ip, '.')), X, 'UniformOutput', false))
The first option is significantly faster (and less to type).
  1 件のコメント
Jay Hanuman
Jay Hanuman 2016 年 11 月 27 日
works thank you.

サインインしてコメントする。

その他の回答 (1 件)

Daniel kiracofe
Daniel kiracofe 2016 年 11 月 27 日
strsplit() will split up the strings for you. Then use sprintf() to make the formatting
https://www.mathworks.com/help/matlab/ref/strsplit.html

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by