Borrar filtros
Borrar filtros

All possible permutations of rows in table and generate variables.

2 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Baltam
Baltam el 22 de Abr. de 2016
Editada: Baltam el 22 de Abr. de 2016
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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by