English 中文(简体)
矩阵模式
原标题:Matrix patterns

我有两个9x9个矩阵,A和B。

我想建立一个大的矩阵C,其模式如下:

 A B B B B B
 B A B B B B
 B B A B B B
 B B B A B B
 B B B B A B
 B B B B B A

As you can see, the A matrices are on the diagonal, the B are everywhere else. I m trying to create a code so that this pattern continues no matter how great the dimensions are.

E.g. 10 matrices x 10 matrices still has matrix A along the diagonal and B s everywhere else.

最好使用马hor和散射或像混血这样的东西? 我不将这些矩阵表A和B已经包含信息。

感谢大家花时间阅读。

最佳回答

如何(定义)

maskcell = repmat( {ones(size(A))}, 1, 10 );
maskdiag = blkdiag( maskcell{:} );
AA = repmat( {A}, 1, 10 );
AD = blkdiag( AA{:} );
BB = repmat( B, 10, 10 );
C = BB .* (maskdiag == 0) + AD

在下文完全有效的评论之后,我添加了面罩,以确保正确的东西从C中挑选。

问题回答

C=B(~eye(size(B))+A(eye(size(A)))应当获得你想要的东西。 或许可以更快地将眼睛的使用结合起来......

kron(eye(10), A) + kron(~eye(10), B)





相关问题
Matrix to Represent a Triangle in Screen Space

So i have a set of four points in 3D Space. P1 [0, 0, 0] P2 [128, 0, 0] P3 [0, 128, 0] P4 [128, 128, 0] Which I m then projecting orthographically to the screen effectively giving me two ...

Multiply a 3D matrix with a 2D matrix

Suppose I have an AxBxC matrix X and a BxD matrix Y. Is there a non-loop method by which I can multiply each of the C AxB matrices with Y?

matrix and vector template classes in c++

#include <array> template <typename T> class Vector4<T> { std::array<T, 4> _a; // or T _a[4]; ? }; template <typename T> class Matrix4<T> { std::array<...

Linear Independence Matrix

Suppose we have a m by n matrix A with rank m and a set K⊆{1..n} such that the columns of A indexed by K are linearly independent. Now we want to extend K and find a set L so that k⊆L and columns ...

Difference between MATLAB s matrix notations

How do you read the following MATLAB codes? #1 K>> [p,d]=eig(A) // Not sure about the syntax. p = 0.5257 -0.8507 -0.8507 -0.5257 d = ...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Java large datastructure for storing a matrix

I need to store a 2d matrix containing zip codes and the distance in km between each one of them. My client has an application that calculates the distances which are then stored in an Excel file. ...

Checking row and column for a word in python

I am trying to create a checking program to see if the word is in a matrix horizontally or vertically. I have the code for checking the row, but would checking the column be similar to the row code? ...

热门标签