Arrays Matlab中一维级联单元阵列
我在Matlab中有一个二维表格单元,Arrays Matlab中一维级联单元阵列,arrays,matlab,concatenation,cell-array,Arrays,Matlab,Concatenation,Cell Array,我在Matlab中有一个二维表格单元,B,即: A = table(normrnd(0,1,5,1),normrnd(0,1,5,1),normrnd(0,1,5,1)); B = {A,A,A,A;A,A,A,A} B = [5x3 table] [5x3 table] [5x3 table] [5x3 table] [5x3 table] [5x3 table] [5x3 table] [5x3 table] 我希望在单元格数组的第1维(2行)中
B
,即:
A = table(normrnd(0,1,5,1),normrnd(0,1,5,1),normrnd(0,1,5,1));
B = {A,A,A,A;A,A,A,A}
B =
[5x3 table] [5x3 table] [5x3 table] [5x3 table]
[5x3 table] [5x3 table] [5x3 table] [5x3 table]
我希望在单元格数组的第1维(2行)中连接表,但在另一维中保留单元格结构。因此,我希望有以下几点:
{cat(1,B{:,1}),cat(1,B{:,2}),cat(1,B{:,3}),cat(1,B{:,3})}
ans =
[10x3 table] [10x3 table] [10x3 table] [10x3 table]
然而,由于我的实际单元数组有多于2行4列,所以这不是一个合适的解决方案。我尝试过使用cat
和vertcat
,但我无法让它们在第二维度中不连接。使用“cat”,我得到:
cat(1,B{:})
ans =
[40x3 table]
有什么想法吗
谢谢 试试这个:
result = cellfun(@(a,b) cat(1,a,b),B(1,:),B(2,:),'UniformOutput',false);
输出:
result =
[10x3 table] [10x3 table] [10x3 table] [10x3 table]
(我们需要将UniformOuput
设置为false
,因为输出单元格的内容不是标量。)
在我的案例中,其中一个单元格的内容:
result{1}
ans =
Var1 Var2 Var3
________ _______ ________
-0.20497 0.6715 1.0347
-0.12414 -1.2075 0.72689
1.4897 0.71724 -0.30344
1.409 1.6302 0.29387
1.4172 0.48889 -0.78728
-0.20497 0.6715 1.0347
-0.12414 -1.2075 0.72689
1.4897 0.71724 -0.30344
1.409 1.6302 0.29387
1.4172 0.48889 -0.78728
我应该提到这一点,但我真正的单元数组也有很多行,所以我需要一个解决方案,不需要为每一行(B(1,:),B(2,:),…)添加单元数组。我脑子里想不出一个解决方案,如果不使用
for
循环。如果我有什么想法,我会再次发表评论。@Mace您的表中有什么类型的数据?如果都是数字,我们可以用cell2mat
和mat2cell
做一些事情,但我怀疑也有像变长字符串这样的东西?是的,会有字符串和数字数据