Suppose I have a struct array in MATLAB:
a= struct('a1',{1,2,3},'a2',{4,5,6})
How can I efficiently (i.e. with vectorized code) filter the elements of the struct so that they satisfy some boolean property?
For instance:
- How would I create a new struct array
bwhose elements are the subset ofawhere botha1is a multiple of 3 anda2is a multiple of 3? The expected result is a struct array of size 1 with the elementstruct('a1', 3, 'a2', 6). - How would I create a new struct array
bwhose elements are the subset ofawherea1is odd ora2is a multiple of 3? The expected result is the following struct array of size 2:struct('a1', {1,3}, 'a2', {4,6}).