Array dimensions must agree vertcat
6 次查看(过去 30 天)
显示 更早的评论
I've been trying to concatenate two cell arrays (both of which are 1x157) and I can use vertcat to do so in using the input/command line but I get an "Dimensions of matrices being concatenated are not consistent.:" error when I do so in a function. Is there anything I can do or will I have to perform the concatenation manually every time I need to?
0 个评论
回答(1 个)
Chad Greene
2015-10-29
My guess is both arrays are not 1x157. Is one of them 157x1? Because this works fine:
x = rand(1,157);
y = rand(1,157);
z = vertcat(x,y);
However,
x = rand(1,157);
y = rand(157,1);
z = vertcat(x,y);
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
2 个评论
Chad Greene
2015-10-29
Are you sure the constants are cells? Because
x = rand(1,157);
y = cell([1 157]);
z = vertcat(x,y);
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
But if you convert x to a cell array it works:
x = rand(1,157);
y = cell([1 157]);
z = vertcat(num2cell(x),y);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!