How to insert the missing number into the cell array?
조회 수: 8 (최근 30일)
이전 댓글 표시
Suppose that I have this
I=[3 5 6 8 10 11]
A={[3];[6;8];[];[11]}
How to find the missing number of I in A and insert that number into any position of A? for intance like:
A={[3];[6;8];[5];[10;11]}
댓글 수: 4
Akira Agata
2019년 5월 14일
편집: Akira Agata
2019년 5월 14일
One quick question:
How did you define the position of '10' in your cell array A?
채택된 답변
KSSV
2019년 5월 14일
I=[3 5 6 8 10 11] ;
A={[3];[6;8];[];[11]} ;
% get empty cell
idx = cellfun(@isempty,A) ;
A{idx} = setdiff(I,cell2mat(A))
댓글 수: 11
KSSV
2019년 5월 14일
I=[3 5 6 8 10 11] ;
A={[3];[6;8];[];[11]} ;
% get empty cell
idx = cellfun(@isempty,A) ;
missing = setdiff(I,cell2mat(A)) ;
A{idx} = missing(1)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!