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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:12:55+00:00 2026-05-28T06:12:55+00:00

I have an array (M) of matrices. I perform an operation on the matrix

  • 0

I have an array (M) of matrices. I perform an operation on the matrix in the ith position, and it adds three more matrices to my array in the (3i-1), (3i) and (3i+1)th positions. I want to continue this process until I reach the jth position in the array, where j is such that all matrices in the (j+1)th position and onwards have appeared already somewhere between positions 1 and j (inclusive).

EDIT: I’ve been asked to clarify what I mean. I am unable to write code that makes my algorithm terminate when I want it to as explained above. If I knew a proper way of searching through an array of matrices to check if a given matrix is contained, then I could do it. I tried the following:

done = 0;    

ii = 1

    while done ~= 1

    %operation on matrix in ith position omitted, but this is where it goes

        for jj = ii+1:numel(M)

                for kk = 1:ii
                    if M{jj} == M{kk};
                        done = done + 1/(numel(M) - ii);
                        break
                    end
                end
        end

            if done ~= 1
                done = 0;
            end

    ii = ii + 1

    end

The problem I have with this (as I’m sure you can see) is that if the process goes on for too long, rounding errors stop ever allowing done = 1, and the algorithm doesn’t terminate. I tried getting round this by introducing thresholds, something like

while abs(done - 1) > thresh

and

if abs(done - 1) > thresh
    done = 0;
end

This makes the algorithm work more often, but I don’t have a ‘one size fits all’ threshold that I could use (the process could continue for arbitrarily many steps), so it still ends up breaking.

What can I do to fix this?

Thanks

  • 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-05-28T06:12:56+00:00Added an answer on May 28, 2026 at 6:12 am

    Why don’t you initialize done at 0, keep your while done==0 loop, and instead of computing done as a sum of elements, check if your condition (finding if the matrix already exists) is verified for all jj, something like this:

    alldone=zeros(numel(M)-ii,1);
    
    for jj = ii+1:numel(M)
    
            for kk = 1:ii
                if isequal(M{jj},M{kk})
                    alldone(jj-ii) = 1
                    break
                end
            end
    end
    done=prod(alldone);
    

    There is probably a more elegant way to code this, though.
    For instance, you could add early termination:

    while done==0
    done=1;
    for jj = ii+1:numel(M)
        match_success=0;
        for kk = 1:ii
            if isequal(M{jj},M{kk})
                match_success=1;
                break
            end
        end
        if match_success==0
            done=0;
            break;
        end
    end
    end
    

    At the beginning of each loop, the algorithm assumes it is going to succeed and stop there (hence the done=1). Then for each jj, we create a match_success which will be set to 1 only if a match is found for M{jj}. If the match is found, we break and go to the next j. If no match if found for j, match_success is left to 0, done is initialized to 0 and the while loop continues. I haven’t checked it, but I think it should work.

    This is just a simple tweak, but again, more thought can probably speed up this whole code a lot.

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

Sidebar

Related Questions

I have a matrix A and I want 2 matrices U and L such
I have both matrices containing only ones and each array has 500 rows and
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
VISUAL C++ Question Hi, I have array of 3 elements and I want to
I have an array in Perl: my @my_array = (one,two,three,two,three); How do I remove
this is really strange, i have an array in delphi and fill it with
I need to have a 4x4 matrix like this: 1 2 3 4 5
I have a large array 15x15x2200. THis is merely a collection of 15x15 sparse
I have a 2D numpy array (i.e matrix) A which contains useful data interspread
Say I have a cell array, that holds a stack of logical matrices, e.g.

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.