Question: I can convert the excel file to text manually inside of Excel.

However to make my MATLAB scripts more autonomous and not relying on

another application, I am struggling with converting a .xlsx file to

text inside of MATLAB. Is there a function or routine to convert a

.xlsx file to .txt?

Answer: 
Building on Brian's suggestion, this is much more legible and works well.

```
scope :near, lambda { |postal_code, miles|
  degree_offset = miles / MILES_PER_DEGREE / 2
  where("latitude > :min_lat and latitude < :max_lat and longitude > :min_lon and longitude < :max_lon",
    min_lat: postal_code.latitude - degree_offset,
    max_lat: postal_code.latitude + degree_offset,
    min_lon: postal_code.longitude - degree_offset,
    max_lon: postal_code.longitude + degree_offset)
}

def postal_code_ids_within(miles)
  self.class.near(self, miles).pluck(:id)
end

```
Breaking up into scopes is a good suggestion. In contrast to another answer I prefer defining complicated scopes as a function instead of messing with lambdas, blocks and [precedence rules](https://stackoverflow.com/questions/1476678/rails-named-scope-lambda-and-blocks):

```
def self.near(postal_code, miles)
  degree_offset = miles / MILES_PER_DEGREE / 2
  where("latitude > :min_lat and latitude < :max_lat and longitude > :min_lon and longitude < :max_lon",
    min_lat: postal_code.latitude - degree_offset,
    max_lat: postal_code.latitude + degree_offset,
    min_lon: postal_code.longitude - degree_offset,
    max_lon: postal_code.longitude + degree_offset)
end

def postal_code_ids_within(miles)
  self.class.near(self, miles).pluck(:id)
end

```