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!