如何创建Matlab 201X 201矩阵 [英] How do I create a matlab 201X 201 matrix
问题描述
如何创建一个201x 201矩阵,所有奇数行交替为3,1,3,偶数行交替为1,2,1,2.我尝试使用随机数生成器,for循环,并正在考虑使用find命令.我正在尝试生成矩阵,但是收到了错误消息.
How do I create a 201x 201 matrix with all odd rows alternating as 3,1,3 and the even rows alternating as 1,2,1,2. I tried using a random number generator, a for loop, and am thinking about using the find command. I am trying to generate a matrix, but I have recieved error messages.
推荐答案
如果我正确理解您的意思,那么Kronecker产品(kron
)是实现此目的的最简单方法:
If I understand what you mean correctly, then the Kronecker product (kron
) is the simplest way to achieve this:
A = kron( ones(101), [3 1; 1 2]);
A = A(1:201, 1:201);
第一个命令根据您的要求创建一个202x202矩阵,第二个命令将第1行和第1列切掉以符合201x201尺寸规格.
The first command creates a 202x202 matrix according to your requirements, and the second command chops 1 row and 1 column off to conform to the 201x201 size specification.
这篇关于如何创建Matlab 201X 201矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!