Filter löschen
Filter löschen

Deleting elements in cell array constrained by logic

5 Ansichten (letzte 30 Tage)
alicia che
alicia che am 10 Mär. 2016
Kommentiert: alicia che am 24 Mär. 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!
  1 Kommentar
alicia che
alicia che am 24 Mär. 2016
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!!

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 10 Mär. 2016
Bearbeitet: Fangjun Jiang am 10 Mär. 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

Weitere Antworten (0)

Kategorien

Mehr zu Data Types finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by