I have an additional problem related to this- I have another cell array C that matches A: A represents onset time points and C are offset time points of the events. When I deleted entries in A with the constrain B, how can I delete those corresponding entries in C? I tried to use A to constrain C, but after the first round of deleting from A, the size changed and the entries in A and C no longer correspond to each other, which is a problem for me...Thanks for helping!!
Deleting elements in cell array constrained by logic
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a cell array for example: A = [{4,2,5},{3,5,7},{2,3,8,},{4,5,6}]. The elements in the cell array are time points in a time series from 0 to 10. I have a binary vector such as B = (0,0,0,1,1,0,0,0,0,0,0), which contains 10 elements (same as the size of the time series). I want to then remove any element in A that corresponding to a "1" in B, in other words remove all the 4s and 5s, to get a new cell array: A_new = [{2},{3,7},{2,3,8,},{6}]. Can anyone help? Thanks!
채택된 답변
Fangjun Jiang
2016년 3월 10일
편집: Fangjun Jiang
2016년 3월 10일
B = [0,0,0,1,1,0,0,0,0,0,0];
A = {[4,2,5],[3,5,7],[2,3,8],[4,5,6]};
NewA=cellfun(@(x) x(~ismember(x,find(B))),A,'uni',false)
% a more readable version would be
TP=find(B);
NewA2=A;
for k=1:numel(A)
Index=ismember(A{k},TP);
NewA2{k}(Index)=[];
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!