Generate a Matrix with the structure in the description
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Fandeu Tchiaga Brice Arsene
el 4 de Dic. de 2020
Comentada: Fandeu Tchiaga Brice Arsene
el 5 de Dic. de 2020
Hi everyone i'm new
i am trying to write an algorithm to generate a matrix which has the following structure
(modified)
1,2
1,3
1,4
.
.
.
and so on till
1,128
then
2,3
2,4
2,5
.
.
an so on till
2,128
and so on till
127,128
after that i wil have to convert it to binary . for it i will use the in bulit de2bi function.
so i have to generate a 2x2 matrix
where the first column starts with 1 and ends with 128 and the second column starts with 2 and repeats everytime 128 is reached.
any suggestion , resources may be of great help.
the only i came up with is this
r1=[1:2]; %for the rows with 1 and inscreasing values of ii
r=[r1];
for ii=1:126
r0=[1:ii+1:ii+2];
r=[r;{r0}];
end
0 comentarios
Respuesta aceptada
Más respuestas (1)
Rik
el 4 de Dic. de 2020
No loops required:
X=tril(ones(128));
[r,c]=find(X);
out=[c r];
For the next step I would suggest you create a cell array with the binary of 1:128, which you can then index. That will prevent a lot of repeated conversions.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!