Generate a Matrix with the structure in the description
1 view (last 30 days)
Show older comments
Fandeu Tchiaga Brice Arsene
on 4 Dec 2020
Commented: Fandeu Tchiaga Brice Arsene
on 5 Dec 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 Comments
Accepted Answer
More Answers (1)
Rik
on 4 Dec 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.
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!