0

I'm really new at matlab and I'm trying to understand this piece of code:

mask = false(size(image_map));
image_map(mask) = -1;

I understand that the first line is to create an array of logical zeros that is the same size as image_map, but what is this image_map(mask) for?

Sorry if it's a dumb question and the answers will be appreciated.

Shai
  • 111,146
  • 38
  • 238
  • 371
Monica
  • 311
  • 1
  • 8
  • 22
  • 1
    since mask is an array of logical zeros, the next line is yields an empty matrix because the index must be a positive integer or logical in the sense of Shai's answer – bla May 05 '13 at 09:33
  • Related question: [How to select a submatrix (not in any particular pattern) in Matlab](http://stackoverflow.com/questions/13091193). – Eitan T May 05 '13 at 09:43

1 Answers1

1

In matlab you may access entries of a matrix is several ways. One is by linear indexing:

image_map( 4 ) % access the fourth element of image_map

However, there is a more efficient way, using logical indexing.
In this approach you create a logical matrix, the same size as image_map and then you can access all the extrines in image_map for which the locial matrix has the value true.

Shai
  • 111,146
  • 38
  • 238
  • 371