【问题标题】:Horizontally concatenate three 1d arrays of different lengths into one 2d array in matlab在matlab中将三个不同长度的一维数组水平连接成一个二维数组
【发布时间】:2014-12-20 15:41:44
【问题描述】:

这可能吗?

假设我在 matlab 中有 3 个不同长度的元胞数组:

"hello"
"hi"

"whats"
"your"
"name"

"how"
"are"
"you"

我想将它们连接成一个二维数组:

"hello" "whats"  "how"
"hi"    "your"   "are"
 0      "name"   "you"

这可能吗?我曾尝试使用 cat() 和 horzcat() 但显然由于矩阵的长度不同,它会出现错误。

【问题讨论】:

  • 如果您的单元格字符串是变量abc,则显式添加0 填充是最简单的方法:[[a;0],b,c]

标签: arrays matlab matrix merge concatenation


【解决方案1】:

根据 MA​​TLAB 的帮助,

Concatenating arrays next to one another using commas is called horizontal concatenation. Each array must have the same number of rows. Similarly, when the arrays have the same number of columns, you can concatenate vertically using semicolons.

所以这是不可能的,因为你的数组应该有不同长度的行。

我认为你最好的选择是使用cell

【讨论】:

    猜你喜欢
    • 2023-03-05
    • 2017-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多