what is the short code for the following?
조회 수: 1 (최근 30일)
이전 댓글 표시
ket0=[1;0;0;0;0;0;0;0;0;0;0;0;0;0];
ket1=[0;1;0;0;0;0;0;0;0;0;0;0;0;0];
ket2=[0;0;1;0;0;0;0;0;0;0;0;0;0;0];
ket3=[0;0;0;1;0;0;0;0;0;0;0;0;0;0];
ket4=[0;0;0;0;1;0;0;0;0;0;0;0;0;0];
ket5=[0;0;0;0;0;1;0;0;0;0;0;0;0;0];
ket6=[0;0;0;0;0;0;1;0;0;0;0;0;0;0];
ket7=[0;0;0;0;0;0;0;1;0;0;0;0;0;0];
ket8=[0;0;0;0;0;0;0;0;1;0;0;0;0;0];
ket9=[0;0;0;0;0;0;0;0;0;1;0;0;0;0];
ket10=[0;0;0;0;0;0;0;0;0;0;1;0;0;0];
ket11=[0;0;0;0;0;0;0;0;0;0;0;1;0;0];
ket12=[0;0;0;0;0;0;0;0;0;0;0;1;0;0]
ket13=[0;0;0;0;0;0;0;0;0;0;0;0;1;0]
ket14=[0;0;0;0;0;0;0;0;0;0;0;0;0;1]
bra0=ctranspose(ket0)
bra1=ctranspose(ket1)
bra2=ctranspose(ket2)
bra3=ctranspose(ket3)
bra4=ctranspose(ket4)
bra5=ctranspose(ket5)
bra6=ctranspose(ket6)
bra7=ctranspose(ket7)
bra8=ctranspose(ket8)
bra9=ctranspose(ket9)
bra10=ctranspose(ket10)
bra11=ctranspose(ket11)
bra12=ctranspose(ket12)
bra13=ctranspose(ket13)
bra14=ctranspose(ket14)
댓글 수: 0
채택된 답변
the cyclist
2023년 1월 8일
It's a little tricky to answer this, without knowing how you plan to use these variables afterward. But,
ket = eye(14);
bra = ctranspose(ket); % Could also be coded as bra = ket';
Then, whenever you need to refer to, say, the 7th variable, reference the 7th column:
ket(:,7)
댓글 수: 0
추가 답변 (1개)
Sulaymon Eshkabilov
2023년 1월 8일
편집: Sulaymon Eshkabilov
2023년 1월 8일
% Simple one is using eye()
KET = eye(14)
BRA = KET; % This is optional: BRA =KET.' gives the same result
ket0=KET(:,1);
ket1=KET(:,2);
...
ket14 = KET(:,14);
bra0 = KET(1,:);
bra1 = KET(2,:);
..
bra14 = KET(14,:);
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!