MATLAB 连接维度不等的矩阵

标签 matlab matrix concatenation

有什么简单的方法可以使用零填充来连接维度不等的矩阵吗?

short = [1 2 3]';
long = [4 5 6 7]';
desiredResult = horzcat(short, long);

我想要这样的东西:

desiredResult = 
1 4 
2 5
3 6
0 7

最佳答案

当您分配给矩阵当前边界之外的索引时,MATLAB 中的矩阵会自动增长并用零填充。例如:

>> short = [1 2 3]';
>> long = [4 5 6 7]';
>> desiredResult(1:numel(short),1) = short;  %# Add short to column 1
>> desiredResult(1:numel(long),2) = long;    %# Add long to column 2
>> desiredResult

desiredResult =

     1     4
     2     5
     3     6
     0     7

关于MATLAB 连接维度不等的矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6208526/

相关文章:

带色 block 的 Matlab 图像图例

matlab - 倍频程图 : how to set the correct position?

performance - 提高具有匿名函数瓶颈的 matlab 代码的性能

r - 在R中创建矩阵的有效方法

java - 如何正确地将滤镜应用于图像阵列?

language-agnostic - 如何存储对称矩阵?

hive - 在配置单元中连接字符串列

Matlab:计算两个图之间的平移

Excel/VBA : Variable Value/Text into concatenate formula

linux - 使用 linux 从文件中加入行