All possible permutations of rows in table and generate variables.
2 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!