一次复制矩阵 [英] Replicate matrix one row at a time

查看:74
本文介绍了一次复制矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有矩阵

A = [1;2;3]

我如何复制A四次,每行复制四次,然后再移至下一行以获得

How do I replicate A four times, replicating each row four times before moving onto the next, to get

[1;1;1;1;2;2;2;2;3;3;3;3;4;4;4;4]

?

推荐答案

在这种特定情况下,您可以按照以下方式进行操作

In this particular instance, you could do something along the lines of

A = [1;2;3;4];
B = repmat(A',4,1);
B = B(:);

这是复制A'以创建矩阵B:

 1     2     3     4
 1     2     3     4
 1     2     3     4
 1     2     3     4

然后使用B(:)将其转换为单列.

It then converts it to a single column using B(:).

这篇关于一次复制矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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