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 8129059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:08:51+00:00 2026-06-06T08:08:51+00:00

I here by post the code why I came across while exploring one technique.

  • 0

I here by post the code why I came across while exploring one technique.

   Y = repmat((1:m)', [1 n]);
   X = repmat(1:n, [m 1]) - labels_left;
   X(X<1) = 1;
   indices = sub2ind([m,n],Y,X);

  final_labels = labels_left;
  final_labels(abs(labels_left - labels_right(indices))>=1) = -1;

In above code labels left is single channel image.[m n] is the size of that image. I want to know how this sub2ind works in above code.And Iam also facing problem in the last statement which contains

  labels_right(indices)

what the above expression evaluates to.Here labels right is also an image

  • 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-06T08:08:52+00:00Added an answer on June 6, 2026 at 8:08 am

    Maybe a smaller example could help understand:

    %# image matrix
    M = rand(4,3)
    [m n] = size(M)
    
    %# meshgrid, and convert to linear indices
    [X,Y] = meshgrid(1:n,1:m)
    indices = sub2ind([m,n],Y,X)
    
    %# extract those elements
    M(indices)
    

    The matrix M:

    >> M
    M =
          0.95717      0.42176      0.65574
          0.48538      0.91574     0.035712
          0.80028      0.79221      0.84913
          0.14189      0.95949      0.93399
    

    the grid of (x,y) coordinates of all points:

    >> X,Y
    X =
         1     2     3
         1     2     3
         1     2     3
         1     2     3
    Y =
         1     1     1
         2     2     2
         3     3     3
         4     4     4
    

    converted to linear indices:

    >> indices
    indices =
         1     5     9
         2     6    10
         3     7    11
         4     8    12
    

    then we index into the matrix using those indices.

    >> M(indices)
    ans =
          0.95717      0.42176      0.65574
          0.48538      0.91574     0.035712
          0.80028      0.79221      0.84913
          0.14189      0.95949      0.93399
    

    Note that: M(indices(i,j)) = M(Y(i,j)),X(i,j)).

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

Sidebar

Related Questions

first post here, and probably an easy one. I've got the code from Processing's
I came across this post here (link below) and it states that you can
I'm trying out code igniter, and I came across an error message while trying
Well I was reading this post and then I came across a code which
I came across this plain js ajax upload code (it seems that jquery $.post
Whilst trying to pivot a sql table I came across this post Here .
here is my code in Controller var q = context.post; return View(q); in view
I got some sample code from the net here: http://www.javadb.com/sending-a-post-request-with-parameters-from-a-java-class That works fine. It
I am trying to get some form data from POST method. Here's the code
I'm using a shopping cart script from a tutorial I came across a while

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.