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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:31:11+00:00 2026-06-16T13:31:11+00:00

I tried to solve this problem, but I could not implement. Could you help

  • 0

I tried to solve this problem, but I could not implement.
Could you help me anything for this?

Problem

Mat1 | Mat2 | Mat3

 1 2 | 1 3  | 2 6

 1 3 | 2 6  | 2 5

 2 4 | 3 1  | 3 1

 3 1 | 3 5  | 5 2

 4 5 |

When there are 3 matrices(for example above), I want to get this result for the intersection rows in [column1 column2 matrixnumber] form.

The result for above example would be

1 3 1

1 3 2

2 6 2

2 6 3

3 1 1

3 1 2

3 1 3

It would be OK if the result is in the form [column1 column2 firstmatrix secondmatrix, ...]

1 3 1 2

2 6 2 3

3 1 1 2 3

For this problem, I want to use at most one for-loop.

Do you have any idea for this?

  • 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-16T13:31:12+00:00Added an answer on June 16, 2026 at 1:31 pm

    Here an alternative solution (which seems to run faster than Gunther’s) using MATLAB’s intersect:

    Mat = {[1 2; 1 3; 2 4; 3 1; 4 5],
           [1 3; 2 6; 3 1; 3 5],
           [2 6; 2 5; 3 1; 5 2]};
    
    result = zeros(sum(cellfun(@(x)size(x, 1), Mat)), 3); % # Preallocate memory
    k = 1;
    for cc = transpose(nchoosek(1:numel(Mat), 2))
        x = intersect(Mat{cc}, 'rows');                   % # Find intersection
        y = ones(size(x, 1), 2) * diag(cc);               % # Generate matrix indices
        result(k:k + numel(y) - 1, :) = [[x; x], y(:)];
        k = k + numel(y);
    end
    
    result(all(~result, 2), :) = [];                      % # Discard zero rows
    result = unique(result, 'rows');                      % # Discard repeated rows
    

    The matrix result should now contain the unique intersection rows and their corresponding matrix indices, just like you want:

    result =   
         1     3     1
         1     3     2
         2     6     2
         2     6     3
         3     1     1
         3     1     2
         3     1     3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried many ways to solve this problem but none works. suppose I have
Firstly I tried fiding some similar posts but could not quite find anything. Mainly
I tried everything I know to solve this problem, but no success. My site
First i couldn't start MSDTC service.I tried following link and solve that problem. link
Tried searching the site, but cannot find an answer to my problem: Lets say
[Meta notes: the following question is not answered, but the problem that the question
I see how to solve the problem but it bothers me that I don't
I think I understand the error message: CoreData could not fulfill a fault, but
I tried to implement a simple login system with Mongodb and Node.js, but I
I tried to solve problems from Project Euler. I know my method would work

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.