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
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
alicia che
il 10 Mar 2016
Commentato: alicia che
il 24 Mar 2016
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!
Risposta accettata
Fangjun Jiang
il 10 Mar 2016
Modificato: Fangjun Jiang
il 10 Mar 2016
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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Types in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!