Matlab 不同行数矩阵拼接
来源:互联网 发布:数据库编程题 编辑:程序博客网 时间:2024/05/15 13:53
遇到一个不同行数矩阵拼接问题,例如
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矩阵拼接
- matlab 矩阵合并、拼接
- Matlab矩阵的拼接
- matlab 矩阵合并、拼接
- MATLAB矩阵的拼接
- matlab如何拼接矩阵
- matlab 矩阵合并、拼接
- matlab-table行数不同(已解决)
- MATLAB利用cat函数拼接矩阵
- 清晨晓叙:matlab中的矩阵拼接
- Matlab提取矩阵规模信息(行数及列数)
- matlab矩阵中每一行数除以一个数
- matlab之size:返回矩阵的行数和列数
- matlab获得矩阵行数或列数的函数:
- matlab中 字符串的拼接、生成字符矩阵
- matlab unique找出矩阵中不同元素
- matlab unique找出矩阵中不同元素
- [DP] BZOJ4300: 绝世好题
- 详解Java8特性之接口默认方法
- sublime3生成html头部按tab键没反应
- git commit 提示错误
- BlockingQueue的使用
- Matlab 不同行数矩阵拼接
- 从程序员到项目经理(三):认识项目经理
- 在Oracle中设置主键自增
- 引导页高亮小提示
- Visionect Software Suite Requirment
- python-18-如何将文件映射到内存?
- 关于centOS7上的iptables防火墙的一些配置和策略
- Ubuntu 16.04 利用qemu模拟ARM开发板
- apache HttpClient的使用