generating matrices from another matrix

1 view (last 30 days)
TADMON YAYA
TADMON YAYA on 6 Dec 2022
Answered: Jan on 6 Dec 2022
x = [1,0,0,1,0,1]
x = 1×6
1 0 0 1 0 1
d = diag(x)
d = 6×6
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
I want to generate matrices from the matrix d so that it gives me the shares below;
Share 1:
1 1 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 1 0 0
0 0 0 0 0 0
0 0 0 0 0 1
Share 2:
1 0 1 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 1 0 0
0 0 0 0 0 0
0 0 0 0 0 1
Share 3:
1 0 0 1 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 1 0 0
0 0 0 0 0 0
0 0 0 0 0 1
etc.
But I don't know how to do it. Can somebody help me ?

Answers (2)

David Hill
David Hill on 6 Dec 2022
x = [1,0,0,1,0,1];
d = diag(x);
s(:,:,1)=d;
for k=2:10
t=d;t(k)=1;
s(:,:,k)=t';
end
s
s =
s(:,:,1) = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 s(:,:,2) = 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 s(:,:,3) = 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 s(:,:,4) = 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 s(:,:,5) = 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 s(:,:,6) = 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 s(:,:,7) = 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 s(:,:,8) = 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 s(:,:,9) = 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 s(:,:,10) = 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1

Jan
Jan on 6 Dec 2022
x = [1,0,0,1,0,1];
d = diag(x);
Share1 = d;
Share1(1, 2) = 1;
Share2 = d;
Share2(1, 3) = 1;
Share3 = d;
Share3(1, 4) = 1;
Or with a loop:
x = [1,0,0,1,0,1];
d = diag(x);
Share = repmat(d, 1, 1, 4);
for k = 1:3
Share(1, k+1, k) = 1;
end
Now Share(:, :, 2) is e.g. Share2 from the first method. Remember that hiding indices in the names of variables is a bad design.

Community Treasure Hunt

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

Start Hunting!