generating matrices from another matrix

조회 수: 1 (최근 30일)
TADMON YAYA
TADMON YAYA 2022년 12월 6일
답변: Jan 2022년 12월 6일
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 ?

답변 (2개)

David Hill
David Hill 2022년 12월 6일
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 2022년 12월 6일
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.

카테고리

Help CenterFile Exchange에서 Video capture and display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by