嗨我有一个4x4双矩阵A
1+2i 2-1i -3-2i -1+4i
3-1i -3+2i 1-3i -1-3i
4+3i 3+5i 1-2i -1-4i
4+2i -5-2i 2+3i 2-1i
这是我的MATLAB代码:
for n=1:1:4
for k=1:1:4
temp=A(n,k);
rea=real(temp);
img=imag(temp);
Distance1(n,k)=sqrt(((rea-1).^2)+((img-1).^2));
Distance2(n,k)=sqrt(((rea+1).^2)+((img-1).^2));
Distance3(n,k)=sqrt(((rea+1).^2)+((img+1).^2));
Distance4(n,k)=sqrt(((rea-1).^2)+((img+1).^2));
Distance(n,k)=min([Distance1(n,k); Distance2(n,k); Distance3(n,k); Distance4(n,k)]);
Decision(n,k)=?
end
end
如何制作一个应该是1 + j,1-j,-1 + j,-1-j的决策矩阵,如下面的示例矩阵一样?
1+i 1-i -1-i -1+i
1-i -1+i 1-i -1-i
1+i 1+i 1-i -1-i
1+i -1-i 1+i 1-i
答案 0 :(得分:6)
怎么样?:
B = sign(real(A))+sign(imag(A))*1i;
另一种变体是:
B = complex(sign(real(A)),sign(imag(A)));