通过多次合并同一行向量来构建矩阵 [英] Building a matrix by merging the same row vector multiple times

查看:55
本文介绍了通过多次合并同一行向量来构建矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有matlab函数可以执行以下操作吗?

Is there a matlab function which allows me to do the following operation?

x = [1 2 2 3];

,然后基于 x ,我想构建矩阵 m = [1 2 2 3;1 2 2 3;1 2 2 3;1 2 2 3]

and then based on x I want to build the matrix m = [1 2 2 3; 1 2 2 3; 1 2 2 3; 1 2 2 3]

推荐答案

您正在寻找 REPMAT 函数:

x = [1 2 2 3];
m = repmat(x,4,1);

您还可以使用索引来重复行:

You can also use indexing to repeat the rows:

m = x(ones(4,1),:);

甚至是外部产品:

m = ones(4,1)*x;

,也使用BSXFUN:

and also using BSXFUN:

m = bsxfun(@times, x, ones(4,1))

这篇关于通过多次合并同一行向量来构建矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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