Matlab元胞数组的合并
2行4列元胞结构如下:a='g1''g2'[][]'g3''g4''g5'[]如何将a合并为1行5列的结构:{'g1''g2''g3''g4''g5'}?...
2行4列元胞结构如下:
a=
'g1' 'g2' [] []
'g3' 'g4' 'g5' []
如何将a合并为1行5列的结构:{'g1' 'g2' 'g3' 'g4' 'g5'}? 展开
a=
'g1' 'g2' [] []
'g3' 'g4' 'g5' []
如何将a合并为1行5列的结构:{'g1' 'g2' 'g3' 'g4' 'g5'}? 展开
展开全部
a={'g1' 'g2' [] []
'g3' 'g4' 'g5' []};
a=reshape(a',1,8);
>> a(3:4)=[]
a =
'g1' 'g2' 'g3' 'g4' 'g5' []
>> a(6)=[]
a =
'g1' 'g2' 'g3' 'g4' 'g5'
'g3' 'g4' 'g5' []};
a=reshape(a',1,8);
>> a(3:4)=[]
a =
'g1' 'g2' 'g3' 'g4' 'g5' []
>> a(6)=[]
a =
'g1' 'g2' 'g3' 'g4' 'g5'
追问
有没有更简单的方法呢?如果a=cell(100,100)规模的呢?
追答
a={'g1' 'g2' [] []
'g3' 'g4' 'g5' []};
[m,n]=size(a);
a=reshape(a',1,m*n);
b=cell(1,m*n);
j=1;
for i=1:m*n
if ~isempty(a{i})
b{j}=a{i};
j=j+1;
end
end
b(j:end)=[];
>>b =
'g1' 'g2' 'g3' 'g4' 'g5'
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询