如何在Matlab中创建此矩阵?

Jac*_*cob 5 matlab

我正在尝试解决Code Golf:Build Me an Arc问题.我的解决方案还不错,但我认为,有一种更简单的方法.有人知道如何生成这样的nxn矩阵n吗?我花了57个字来得到它!

 3     0     0     0     2     0     0     0     1
 0     3     0     0     2     0     0     1     0
 0     0     3     0     2     0     1     0     0
 0     0     0     3     2     1     0     0     0
 4     4     4     4     8     8     8     8     8
 0     0     0     5     6     7     0     0     0
 0     0     5     0     6     0     7     0     0
 0     5     0     0     6     0     0     7     0
 5     0     0     0     6     0     0     0     7
Run Code Online (Sandbox Code Playgroud)

我想打破这些矩阵中的一些.

更新:

这就是我现在的方式.

%%# Create the grid
[X Y]=meshgrid(-r:r);
%%# Compute the angles in degrees
T=atan2(-Y,X)/pi*180;
%%# Get all the angles
T=T+(T<=0)*360;
Run Code Online (Sandbox Code Playgroud)

如您所见,我不需要大部分条目T.

Amr*_*mro 1

由于这与 Code Golf 问题相关,请考虑:

[X Y]=meshgrid(r:-1:-r,-r:r);
T=180+atan2(Y,X)*180/pi;
Run Code Online (Sandbox Code Playgroud)

这将为您节省 3 个角色...