Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:24:43+00:00 2026-06-14T04:24:43+00:00

I am trying to write a function [offset,coffset]=findLowNhbr(map) that for each pixel in a

  • 0

I am trying to write a function

[offset,coffset]=findLowNhbr(map) 

that for each pixel in a map finds the eight neighbors to the pixel, and returns two matrices with both the row and column offsets to the lowest neighbor (uses the numbers -1, 0 and 1). Border pixels are given 0 offsets for both the row and column, since they do not have neighbors.

Here is what I think the general plan for this function should be:

  1. For each point, find the eight nearest neighbors.
  2. If the neighbor is lower than the point, return -1
  3. If the neighbor is at the same elevation as the point, return 0
  4. If the neighbor is higher than the point, return +1
  5. Store these offsets in two matrices.

I am at a complete loss as to where to start, so any advice or questions are welcome!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:24:44+00:00Added an answer on June 14, 2026 at 4:24 am

    Not entirely sure what you mean, but here’s something to get you well on your way:

    neighbors = cell(size(map));
    
    for ii = 2:size(map,1)-1
        for jj = 2:size(map,1)-1
    
            % current element
            M = map(ii,jj);
    
            % extract neighbors
            N = map(ii-1:ii+i, jj-1:jj+1);
    
            % compare values and store
            neighbors{ii,jj} = M<N - M>N;            
    
        end
    end
    

    This will result in a cell-array neighbors, which contains the same number of elements as map, but each entry looks something like this:

    >> neighbors{2,3}
    ans = 
        0  -1   1
        1   0  -1
        1   0  -1
    

    which is the information on all neighbors of pixel (2,3).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a function that takes two containers of the same
I am trying to write a function that takes File object, offset and byte
Trying to write function that numerize items of list and returns list of tuples
Im trying to write a function named ComputeMaximum that has two parameters, both of
I am trying write a function that generates simulated data but if the simulated
I am trying to write a function that will allow me to browse for
I am trying to write a function that can take three parameters: an SqlDataReader,
I'm trying to write a function that will: If there is no region selected,
I'm trying to write a function that adds a new row that has an
Im trying to write a function that counts down to a date which works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.