How to keep only repetitions that meet certain row assumptions when the matrix is 3D in MATLAB?

I have the following 3D array:

x = randn(31,6,1000);

What I would like to do is to keep only those n repetitions that meet the following conditions:

  1. the rows from 1 to 12 for the first observation must be positive;
  2. the rows from 1 to 12 for the second observation must be positive;
  3. the rows from 1 to 12 for the sixth observation must be positive;

In coding terms:

% keep only the n repetitions out of 1000 that meet:

% 1. x(1:12, 1, :) > 0;
% 2. x(1:12, 2, :) > 0;
% 3. x(1:12, 6, :) > 0;

Can anyone help me?

PS: The dataset is not representative of the original one, it was made just to see how a code would work.


Read more here:

Content Attribution

This content was originally published by Rollo99 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: