Question

Let's suppose that I have a file which contains a struct A <1 x 100>. Each of these 1x1 structures has multiple fields, for example:

A(1).A can take on the values 1 or 2 A(1).B can take on the values 3 or 4 and A(1).C can take on the values of 5 or 6

then there's also A(1).data which is a field consisting of an array of 0s and 1s.

I would like to for example take all the structures in A that meet the criteria of B == 3 and C == 5 and A == 2 and put them in a matrix (for plotting) and a couple other combinations.

of course I could do:

for i = 1:100 
    idx1 = A(i).A == 2 & A(i).B == 3 & A(i).C == 5;
    idx1 = find(idx1 == 1);
    idx2 = ...
    idx3 = ...
    etc.
end

and then use these indices to put all the arrays in data into a new matrix and use that to create my plots etc. ... but I can't help but think that there's probably a much, much better and more common method to go about doing this.

Thanks a lot!

Was it helpful?

Solution

[A.A] == 2 & [A.B] == 3 & [A.C] == 5

This will give you an vector as long as A is where 1's are the elements that meet your criteria.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top