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

  • SEARCH
  • Home
  • 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 8098441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:04:48+00:00 2026-06-05T22:04:48+00:00

Say in Matlab I have a matrix like this: 1 2 3 4 5

  • 0

Say in Matlab I have a matrix like this:

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9

I now need to find submatrixes 3×3 around every element (so each element in turn is the center of a 3×3 submatrix). When in the middle, it is no problem to find fx

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9

which is the submatrix:

2 3 4
2 3 4
2 3 4

But when in the border of the matrix, that is elements in the first og last row or column, it of course isn’t possible to find a 3×3 submatrix. Instead I need the submatrix that fits. In the corner fx I would get

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9

where the submatrix is:

1 2
1 2

and in the middle of the border, I get fx:

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9

which gives:

4 5 6
4 5 6

or as another example:

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9

which gives:

6 7 8
6 7 8

I hope you understand my point. I am missing some feature that lets me find the distance from an element to the border.

I can treat every element as a center of a submatrix, and if I can just test, if the distance from the element to the border is below the submatrix’s border (the submatrix dimension will namely change, to fx a 5×5 submatrix), then I can truncate a part of the submatrix while it is being made.

How do I find the distance from an element to the border of the matrix in the most efficient way?

  • 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-05T22:04:50+00:00Added an answer on June 5, 2026 at 10:04 pm

    Let’s specify the question a bit further: You have a matrix of the size nxm and you pick an element i,j. You want to know the distance of element i,j from the border? That would be: min(i,j,n-i,m-j)

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

Sidebar

Related Questions

Say I have a string in a variable in MATLAB like the following: this
say i have a nvarchar field in my database that looks like this 1,
As a simple example, let's say you have this matrix: M = [omega 1;
Does MATLAB have a blackhole or discard variable? Say I'm doing something like: [
I have a problem. I need to iterate through every element in an n-dimensional
I have a matrix in MATLAB, lets say: a = [ 89 79 96
I have multiple Matlab versions installed on my PC. To say, R2006b, R2009b, R2010a.
Say I have a couple of basic objects like so: [Serializable] public class Base
I have a 3-D grayscale volume corresponding to ultrasound data. In Matlab this 3-D
Say I have a MATLAB object defined in a class file classdef foo properties

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.