[英]Matlab error with vertcat and cell arrays
I'm trying to concatenate two arrays as follows: 我试图连接两个数组,如下所示:
z={ '35' {'test'} ; '45' {'test'}}
z={z{:} ;{'55' {'test'}}}
I would expect the result to be 我希望结果是
{35 {'test'}
45 {'test'}
55 {'test'}}
but instead I get: 但是我得到了:
Error using vertcat 使用vertcat时出错
Dimensions of matrices being concatenated are not consistent. 串联的矩阵尺寸不一致。
What am I forgetting? 我忘记了什么? Thanks. 谢谢。
The error is caused by z{:}
which lists all content of z
'into' a N by 1
vector and when you try to collect all the elements with the outer {}
it throws the error due to mismatching dimensions. 该错误是由z{:}
引起的,它将z
的所有内容 “ N by 1
”列出为N by 1
向量,当您尝试使用外部{}
收集所有元素时,由于尺寸不匹配而引发错误。
You might be using too many { }
and you can concatenate cell arrays with [ ]
: 您可能使用了过多的{ }
并且可以使用[ ]
连接单元格数组:
z = { '35' 'test'
'45' 'test'};
z = [z; {'55' 'test'}]
The command window will display: 命令窗口将显示:
z =
'35' 'test'
'45' 'test'
'55' 'test'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.