如何在Matlab中将矩阵的大小加倍并传播其元素? [英] How to double the size of a matrix and propagate its elements in Matlab?
本文介绍了如何在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!
推荐答案
使用> c0> -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屋!
查看全文