Index a cell array with an cell

3 views (last 30 days)
CSCh
CSCh on 3 Mar 2021
Commented: Jorg Woehl on 8 Mar 2021
Hi all
I have a cell array
C {1x2}
C{1} 1x180 values
C{2} 1x1260 values
and B with the same size containing zeros and ones. Now I want to do something:
C{B}=[]; to delete all entries of C where B contains a one whearas if B contains a zero all values should be maintained.
How can i do this?
Thank you!

Answers (1)

Jorg Woehl
Jorg Woehl on 4 Mar 2021
Hi Christian,
You can pick the corresponding entries for each of the cells of C as follows:
C{i}(B{i}==0)
The results are then easily combined into a new cell array, as shown in this short example:
C = {[1 2 3], [10 11 12 13 14 15 16]}
B = {[0 1 1], [ 0 1 0 0 1 1 0]}
newC = {C{1}(B{1}==0), C{2}(B{2}==0)}
The newC cell array now contains {[1], [10 12 13 16]}.
  4 Comments
Jorg Woehl
Jorg Woehl on 8 Mar 2021
Sounds good - cell arrays can indeed be tricky to create and work with. Thanks for the follow-up.

Sign in to comment.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!