Make very small numbers in complex matrix zero
6 次查看(过去 30 天)
显示 更早的评论
format shortG
a11 = 0;
a12 = exp(-j*0.5*pi);
a21 = exp(-j*0.5*pi);
a22 = 0;
S = [a11, a12; a21, a22]
A = ((1+a11)*(1-a22)+a12*a21)/(2*a21);
B = ((1+a11)*(1+a22)-a12*a21)/(2*a21);
C = ((1-a11)*(1-a22)-a12*a21)/(2*a21);
D = ((1-a11)*(1+a22)+a12*a21)/(2*a21);
X = [A, B; C, D]
X_cleanup = X;
X_cleanup(abs(X_cleanup)<0.0001) = 0
Is there a way to automatically ask matlab to output matrix like what's in the X_cleanup instead of X?
Is there anyting under 'format'?
2 个评论
回答(1 个)
Matt J
2021-10-5
编辑:Matt J
2021-10-5
Is there a way to automatically ask matlab to output matrix like what's in the X_cleanup instead of X?
No, but note that if you expect your input data to be integer-valued, you can avoid the issue by generating them in integer form directly:
format shortG
a11 = 0;
a12 = -1i;
a21 = -1i;
a22 = 0;
S = [a11, a12; a21, a22]
A = ((1+a11)*(1-a22)+a12*a21)/(2*a21);
B = ((1+a11)*(1+a22)-a12*a21)/(2*a21);
C = ((1-a11)*(1-a22)-a12*a21)/(2*a21);
D = ((1-a11)*(1+a22)+a12*a21)/(2*a21);
X = [A, B; C, D]
5 个评论
Matt J
2021-10-5
Well like I said, you can't make Matlab truncate results to zero on autopilot.
I think you would regret it even if it were implementable. In the situation you describe, Matlab would have no way of knowing if a computation was the final one or just an intermediate step in a future computation you are planning, so basically truncation would occur at every step in your computational pipeline and accumulate unpredictably.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!