如何将矩阵的大小加倍并在 Matlab 中传播其元素? [英] How to double the size of a matrix and propagate its elements in Matlab?

查看:29
本文介绍了如何将矩阵的大小加倍并在 Matlab 中传播其元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个这样的矩阵:

suppose I have a matrix like this:

a = 
    1    2
    3    4

我想将矩阵的大小加倍并创建如下内容:

I want to double the size of matrix and create something like this:

aa = 
     1    1    2    2
     1    1    2    2
     3    3    4    4
     3    3    4    4

这样,第一个矩阵中的每个元素都会传播到更大矩阵中的四个元素.

in this way, each element in the first matrix propagates to four elements in the bigger matrix.

a(i,j) == aa(2*i-1, 2*j-1)
       == aa(2*i  , 2*j-1)
       == aa(2*i-1, 2*j)
       == aa(2*i  , 2*j)

是否有任何预定义的函数可以做到这一点?

is there any predefined functions to do that?

我当然可以通过两个循环来做到这一点,但我想要最简单、最干净的方法!

definitely I can do that by two loops, but I want the easiest and cleanest way!

推荐答案

use kron - Kronecker 张量积:

use kron - Kronecker tensor product:

kron(a,ones(2))


ans =
 1     1     2     2
 1     1     2     2
 3     3     4     4
 3     3     4     4

这篇关于如何将矩阵的大小加倍并在 Matlab 中传播其元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆