遇到一个不同行数矩阵拼接问题,例如

A=[1 2 3 4 5 6]';

B=[1 2 3 4]';

基本想法是将行数小的矩阵补零,凑成行数一致,matlab中扩充矩阵的函数padarray

下面是合并AB矩阵的程序

l=max([length(A),length(B)]);

C=[padarray(A,[l-length(A) 0],'post') padarray(B,[l-length(B) 0],'post')]

程序运行结果

C =

1     1

2     2

3     3

4     4

5     0

6     0

附上Matlab文档中padarray函数的说明:

padarray

Pad(填充) array

Syntax

B = padarray(A, padsize)

B = padarray(A, padsize, padval)

B = padarray(A, padsize, padval, direction)

Description

B = padarray(A, padsize) pads array A with 0's (zeros). padsize is a vector of positive integers that specifies both the amount of padding to add and the dimension

along which to add it. The value of an element in the vector specifies the amount of padding to add. The order of the element in the vector specifies the dimension along which to add the padding.( padsize中第一个元素为填充的行数,第二个元素填充的列数)

For example, a padsize value of [2 3] means add 2 elements of padding along the first dimension(第一维,即行) and 3 elements of padding along the second dimension(第二维,即列).

By default, paddarray adds padding before the first element and after the last element along the specified dimension.

B = padarray(A, padsize, padval) pads array A where padval specifies the value to use as the pad value(填充值,若不填则默认为0). padarray uses the value 0 (zero) as the default.

padval can be a scalar that specifies the pad value directly or one of the following text strings that specifies the method padarray uses to determine the values of the elements added as padding.

Value

Meaning

'circular'

Pad with circular repetition of elements within the dimension(重复元素).

'replicate'

Pad by repeating border elements of array(边界元素).

'symmetric'

Pad array with mirror reflections of itself(镜像元素).

B = padarray(A, padsize, padval, direction) pads A in the direction specified by the string direction. direction can be one of the following strings. The default

value is enclosed in braces ({}).

Value

Meaning

{'both'}

Pads before the first element and after the last array element along each dimension. This is the default(默认填充于元素前和元素后).

'post'

Pad after the last array element along each dimension(填充于元素后).

'pre'

Pad before the first array element along each dimension(填充与元素前).

Class Support

When padding with a constant value, A can be numeric or logical. When padding using the 'circular', 'replicate', or 'symmetric' methods, A can be of any class. B

is of the same class as A.

转载自:http://shanyunh.blog.163.com/blog/static/788787201142544537215/

matlab 拼接矩阵,Matlab 不同行数矩阵拼接相关推荐

  1. matlab矩阵除以一个数字,matlab矩阵中每一行数除以一个数 | 学步园

    例如:用a中每一行数除以x中相对应的每一个数 x=[5 10 6 8 16 6 8 8 22 11]; a=[4 4 4 5 4 4 4 4 3 4 6 8 6 2 6 8 8 6 8 6 4 4 4 ...

  2. matlab矩阵除以一个数字,matlab矩阵中每一行数除以一个数

    例如:用a中每一行数除以x中相对应的每一个数 x=[5 10 6 8 16 6 8 8 22 11]; a=[4 4 4 5 4 4 4 4 3 4 6 8 6 2 6 8 8 6 8 6 4 4 4 ...

  3. matlab 数组 组成 矩阵,MATLAB矩阵与数组

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 MATLAB既然以矩阵实验室命名,就说明该软件在矩阵计算方面具有非常优异的表现.在MATLAB中,一般情况下一个矩阵就是指一个长方形的数组.特殊情况有两个 ...

  4. matlab 全1矩阵,matlab全为1的矩阵

    生成一个 m 行 n 列的零矩阵,m=n 时可简写为 zeros(n) 生成一个 m 行 n 列的元素全为 1 的矩阵, m=n 时可写为 ones(n) 生成一个主对角线全为 1 的 m 行 n 列 ...

  5. 【MATLAB实验】MATLAB矩阵与数组及改变矩阵形状(rot90函数逆时针旋转、矩阵转置)

    目录 Matlab矩阵 矩阵除法 矩阵乘方 数组的乘和除 数组的乘方 数据的输出格式 常用函数的应用 矩阵的建立 冒号表达式 结构矩阵和单元矩阵 结构矩阵: 单元矩阵: 矩阵元素的引用方式 利用冒号表 ...

  6. 如何matlab导入邻接矩阵,“excel如何做矩阵“matlab中读取excle中的邻接矩阵

    怎么在excel中使用矩阵函数 在excel中使用矩阵: 1.矩阵乘法运算择G3:H4,公式:=MMULT(A3:B4,D3:E4) 按Ctrl Shift Enter键,即输组公式. 2.阵的逆矩阵 ...

  7. 自定义Matlab功能函数——10进制整数矩阵转二进制字符矩阵

    不同版本matlab的m语言语法会略有不同,这里使用的版本为Matlab 2021a. 一. 10进制整数矩阵转二进制字符矩阵 因为FPGA只能识别二进制,所以在做Verilog仿真时经常需要matl ...

  8. matlab求零空间,matlab求矩阵的零空间的一组整数基,该怎样操作?

    匿名用户 1级 2015-09-18 回答 第一部分:矩阵基本知识 一.矩阵的创建 直接输入法 利用Matlab函数创建矩阵 利用文件创建矩阵 二.矩阵的拆分 矩阵元素 矩阵拆分 特殊矩阵 三.矩阵的 ...

  9. python读取matlab矩阵_matlab、python中矩阵的互相导入导出方式

    还有一种最流行的h5py.. 过几天更新 ------------在python中导出矩阵至matlab------------ 如果矩阵是mxn维的. 那么可以用 : np.savetxt('dev ...

最新文章

  1. 利用数据存储技术实现数据安全合理备份
  2. 动态创建DeepZoom
  3. Apache 超详细编译参数解析
  4. 网站建设之前需要先了解目标受众
  5. 佳能g3800故障灯说明书_汽车仪表灯的使用方法以及注意事项
  6. cron引起inode节点用光的情况
  7. 数据段描述符和代码段描述符(二)——《x86汇编语言:从实模式到保护模式》读书笔记11
  8. js中var、let、const区别
  9. linux-远程管理-xshell
  10. 关于读研的一些感悟1
  11. 常用的数据结构_动态图展示 6 个常用的数据结构,一目了然
  12. docker安装rabbitmq及简单管理
  13. 黄渤高情商:小S和林志林同时掉到水里,你先救谁
  14. javascript座标_javascript JS元素位置和位置坐标
  15. 高德地图 android api 实现自动定位
  16. UGUI的image
  17. 按键精灵post教程_安卓按键精灵教程VIP按键精灵辅助post视频教程大漠插件编程实战...
  18. 网上教学管理系统的设计与实现
  19. matlab语法 axis on,matlabaxis
  20. 【C语言】动态内存开辟

热门文章

  1. 2016/1/14 java随机数生成
  2. 小公司如何选择合适的信息管理软件
  3. unixodbc mysql安装_ubuntu12下安装unixODBC(mysql)
  4. bootstrap项目实例_101个Python项目打包放送,工作学习必备(源码放送)
  5. 在安卓手机上编写和运行Python 3.x程序
  6. Python使用matplotlib绘制正多边形逼近圆周
  7. Python使用UDP广播实现服务器自动发现
  8. python的基本语法if语句_Python基础之条件控制操作示例【if语句】
  9. C语言 如何计算结构体的大小
  10. 华为服务器gpu卡型号,gpu服务器与配置