All possible permutations of rows in table and generate variables.

2 ビュー (過去 30 日間)
Amritpal Kaur
Amritpal Kaur 2016 年 4 月 22 日
編集済み: Baltam 2016 年 4 月 22 日
So I have rows with the following possible data.
+----------------------------------------------------------------------+----------------------------------------------------------------------+------+------+
| ip | neighbor | val1 | val2 |
+----------------------------------------------------------------------+----------------------------------------------------------------------+------+------+
| can have any random value ranging from 192.168.2.101 - 192.168.2.110 | can have any random value ranging from 192.168.2.101 - 192.168.2.110 | - | - |
+----------------------------------------------------------------------+----------------------------------------------------------------------+------+------+
I know in order to populate a variable with portion of the table I do this (lq being my table variable) :
T = lq(strcmp(lq.ip, '192.168.2.101') & strcmp(lq.neighbor, '192.168.2.102'), :) ;
the problem is that I need to write some code that will store all possible combinations of this ip and neighbor (except where they are same) and store it in a different variable.
That is if I would have to hand code it would be,
T1 = lq(strcmp(lq.ip, '192.168.2.101') & strcmp(lq.neighbor, '192.168.2.102'), :) ;
T2 = lq(strcmp(lq.ip, '192.168.2.101') & strcmp(lq.neighbor, '192.168.2.103'), :) ;
T3 = lq(strcmp(lq.ip, '192.168.2.101') & strcmp(lq.neighbor, '192.168.2.104'), :) ;
.
.
.
T73 = lq(strcmp(lq.ip, '192.168.2.110') & strcmp(lq.neighbor, '192.168.2.101'), :) ;
.
.
T79 = lq(strcmp(lq.ip, '192.168.2.110') & strcmp(lq.neighbor, '192.168.2.109'), :) ;
Is there a faster no naive way to do it? Thanks!

採用された回答

Baltam
Baltam 2016 年 4 月 22 日
編集済み: Baltam 2016 年 4 月 22 日
You can make combinations as follows:
IP = [101:110]; % end part of your IP adresses
combIP = combvec(IP,IP)'; % Make combinations (combvec doesn't exist yet in matlab 2013b)
combIP = combIP(combIP(:,1)~=combIP(:,2),:); % Eliminate double (e.g. [110 110])
From there, you can make strings that use these endings with num2str(combIP(i,j))
Baltam

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by