matlab | logical subscripting – learning notes clearly defines it — “Suppose X is an ordinary matrix and L is a matrix of the same size that is the result of some logical operation. Then X(L)specifies the elements of X where the elements of L are nonzero.”

Note if L has 5 non-zero elements, then length(X(L)) == 5.

I think L must be an array of booleans, not doubles.

For a matrix, see

But here’s a real illustration in my code:

  step = 1/200;
  steps = 2/step;

  % generate increments
  %rng(0,’twister’); % if we want repeatable
  incr = randn(steps,reruns)*sqrt(step);

  std(incr) % should  all be around 0.07

  % random walker positions
  p = cumsum(incr);

  % select a subset of Columns, using filter on
  % “200th ROW and 400th ROW” so
  % row expression = wildcard; column expression = filter on Row.
  % If we carelessly swap the expressions, matlab won’t warn us!
  qualified = p(:, (p(200,:)>0 & p(400,:)>0));

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s