How i can convert cell (each element in cell with different length) to array?

조회 수: 3 (최근 30일)
hello everybody how I can convert this cell to array such that I want each element in cell in row in array
ex = {[1,2,4,5,7,11,12],[1,3,4,5,7,11,12],[1,2,4,6,5,7,11,12],[1,3,4,6,5,7,11,12],[1,2,4,5,8,13,7,11,12],[1,3,4,5,8,13,7,11,12],[1,2,4,6,5,8,13,7,11,12],[1,3,4,6,5,8,13,7,11,12]};
  댓글 수: 1
Stephen23
Stephen23 2018년 6월 1일
편집: Stephen23 2018년 6월 1일
Simpler solution: download Jos' FEX submssion padcat, and use it like this:
padcat(ex{:})

댓글을 달려면 로그인하십시오.

채택된 답변

Anton Semechko
Anton Semechko 2018년 6월 1일

Is this kind of what you are looking for?

ex = {[1,2,4,5,7,11,12],[1,3,4,5,7,11,12],[1,2,4,6,5,7,11,12],[1,3,4,6,5,7,11,12],[1,2,4,5,8,13,7,11,12],[1,3,4,5,8,13,7,11,12],[1,2,4,6,5,8,13,7,11,12],[1,3,4,6,5,8,13,7,11,12]};
n=numel(ex);
N=zeros(n,1);
for i=1:n
    N(i)=numel(ex{i});
    ex{i}=ex{i}(:)';
end
if min(N)<max(N)
    dN=max(N)-N;        
    for i=1:n
        if dN(i)>0
            ex{i}=cat(2,ex{i},nan(1,dN(i)));
        end
    end
end
ex=cell2mat(ex(:));
disp(ex)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by