To combine different cells with empty columns together
1 次查看(过去 30 天)
显示 更早的评论
Hi. I want to combine three different cells in a cell with additional empty columns..
funct1 =
'Q7'
'Q12F'
'Q12G'
'Q12H'
'Q12I'
'Q12L'
'Q12M'
funct2 =
'Q12G'
'Q12H'
'Q12I'
'Q12L'
'Q12M'
funct3 =
'Q12G'
'Q12H'
'Q12I'
Final cell will become like this.
funct =
'Q7' [] 'Q12G' [] 'Q12G' []
'Q12F' [] 'Q12H' [] 'Q12H' []
'Q12G' [] 'Q12I' [] 'Q12I' []
'Q12H' [] 'Q12L' [] [] []
'Q12I' [] 'Q12M' [] [] []
'Q12L' [] [] [] [] []
'Q12M' [] [] [] [] []
Could anyone show me how?
0 个评论
采纳的回答
Andrei Bobrov
2017-7-5
编辑:Andrei Bobrov
2017-7-5
fu ={{
'Q7'
'Q12F'
'Q12G'
'Q12H'
'Q12I'
'Q12L'
'Q12M'};
{'Q12G'
'Q12H'
'Q12I'
'Q12L'
'Q12M'};
{ 'Q12G'
'Q12H'
'Q12I'}};
n = cellfun(@numel,fu);
m = max(n);
k = numel(n);
ou = zeros(m*2*k,1);
n1 = n + 2*(0:k-1)'*m;
n0 = n1 - n + 1;
ou(n0) = 1;
ou(n1+1) = -1;
lo = cumsum(ou);
out = cell(m,2*k);
out(lo > 0) = cat(1,fu{:});
or
n = cellfun(@numel,fu);
m = max(n);
k = numel(n);
out = cell(m,2*k);
for ii = 1:k
out(1:n(ii),2*ii-1) = fu{ii};
end
0 个评论
更多回答(1 个)
KL
2017-7-5
编辑:KL
2017-7-5
funct1 = {'Q7';'Q12F';'Q12G';'Q12H';'Q12I';'Q12L';'Q12M'};
funct2 = {'Q12G';'Q12H';'Q12I';'Q12L';'Q12M'};
funct3 = {'Q12G';'Q12H';'Q12I'};
funct0 = cell(size(funct1));
funct2{length(funct1)}= [];
funct3{length(funct1)}= [];
functt = [funct1 funct0 funct2 funct0 funct3 funct0]
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!