复制矩阵的行或列,并将其插入下一行/列 [英] Copy a row or column of a matrix and insert it in the next row/column

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

问题描述

我想知道如果在MATLAB中有一个简单的方法来执行以下操作:我想复制一个行或列的矩阵,并将其插入下一行/列。

I was wondering if there is an easy way in MATLAB to do the following operation: I'd like to copy a row or column of a matrix and insert it in the next row/column.

例如:给定一个3x3矩阵

For example: given a 3x3 matrix

1 2 3
4 5 6
7 8 9

并将其插入第二行:

1 2 3
1 2 3
4 5 6
7 8 9

有人可以告诉我如何在MATLAB中完成这个任务吗?

Can someone advise how I could accomplish this in MATLAB? Thanks!

推荐答案

您可以简单地重复要重复的行的索引

You can simply repeat the indices of the rows you'd like to repeat

A = A([1 1 2 3],:)

这篇关于复制矩阵的行或列,并将其插入下一行/列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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