필터 지우기
필터 지우기

How do I create a new array each time there is an empty matrix in a cell array.

조회 수: 1 (최근 30일)
I have a cell array and I want to create a new array each time an empty cell is encountered. so for example, I may have: [1 2 3] [4 5 6] [7 8 9] [] [3 2 1] [4 7 6] [] [6 8 7]
So in this case I would want 3 separate arrays created with the following:
array1= [1 2 3 4 5 6 7 8 9] array2= [3 2 1 4 7 6] array3= [6 8 7]

채택된 답변

James Tursa
James Tursa 2017년 10월 12일
편집: James Tursa 2017년 10월 12일
One way:
C = your cell array
x = [0, find(cellfun(@isempty,C)), numel(C)+1];
n = numel(x)-1;
result = cell(1,n);
for k=1:n
result{k} = cell2mat(C(x(k)+1:x(k+1)-1));
end
result(cellfun(@isempty,result)) = [];

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by