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

The Archive Base Latest Questions

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

Supose I have a matrix. This matrix is blank except some points that create

  • 0

enter image description here
Supose I have a matrix. This matrix is blank except some points that create rectangles with the same size. Every point that creates a rectangle has a positive number that is equal for all the points of that rectangle. It is posible that this matrix have several rectangles each with the same number.

Imagine now I have a second matrix with the same structure but now the rectangles are in other positions with an other size and an other values just as matrix A and B in the picture.

I want to combine both matrix so if there’s an intertection of some rectangle, the rectangle with the minimum number is erased.

Which is the best way to do it? I think that it can be posible doing fors but I want to do it 30 times so it will take a lot of time for Octave to complete it if I don’t improve it.

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

    I have made this small code that seem to do the job:

    A=[0 0 1 1 1 0 ;
       0 0 1 1 1 0 ;
       0 0 0 0 0 0 ;
       2 2 0 0 0 0 ;
       2 2 0 0 0 0 ;
       2 2 0 0 0 0 ];
    
    B=[3 0 2 2 0 0 ;
       3 0 2 2 0 0 ;
       0 0 2 2 0 0 ;
       0 0 0 0 0 0 ;
       1 1 1 1 1 0 ;
       1 1 1 1 1 0 ];
    
    
    %give a unique id to each rectangle
    lblA=bwlabel(A);
    lblB=bwlabel(B);
    
    %search for overlap
    overlap= A & B;
    
    % find out overlaping rectangle s unique id
    overlapLbl= unique([lblA(overlap(:)) lblB(overlap(:))],'rows');
    
    %eliminate rectangle with lower score
    for ov=1:size(overlapLbl,1)
      scoreA=A(find((lblA==overlapLbl(ov,1)),1));
      scoreB=B(find((lblB==overlapLbl(ov,2)),1));
      if scoreA>scoreB
        B(B==scoreB)=0;
      else
        A(A==scoreA)=0;
      end
    end
    C=A+B
    

    output:

    C =
         3     0     2     2     0     0
         3     0     2     2     0     0
         0     0     2     2     0     0
         2     2     0     0     0     0
         2     2     0     0     0     0
         2     2     0     0     0     0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose that I have a 2D array (matrix) in Java like this... int[][] MyMat
Suppose, in MATLAB, that I have a matrix, A, whose elements are either 0
Supose I have this string: a= hello world hella warld and I want to
I have a matrix class that takes the row and column reference type that
This bothers me a bit: Suppose you have a matrix with three layers. Is
If I have the original transform matrix of a rectangular UIImageView and this image
Suppose I have a matrix of weights, and another matrix of data values. Can
Suppose I have a matrix foo as follows: foo <- cbind(c(1,2,3), c(15,16,17)) > foo
suppose I have the following matrix a = 2 NaN NaN 4 NaN 3
Suppose you have an NxN matrix and you have to check whether it's a

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.