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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:37:57+00:00 2026-05-19T23:37:57+00:00

I want to create a matrix A [4×8] as follows. The matrix A always

  • 0

I want to create a matrix A [4×8] as follows.

The matrix A always has 1 as its diagonal. A11,A22,A33,A44 = 1

This matrix can be considered as two halves with first half being the first 4 columns and the second half being the second 4 columns like something below :

        1 -1 -1 -1   1 0 0 1
  A =  -1  1 -1  0   0 1 0 0
       -1 -1  1  0   1 0 0 0 
       -1 -1 -1  1   1 1 0 0

Each row in the first half can have either two or three -1’s:

  • if it has two -1‘s then that corresponding row in the second half should have one 1
  • if any row has three -1‘s the second half of the matrix should have two 1‘s.

The overall objective is to have the sum of each row to be 0. I need to generate all possible combinations of a matrix like this.

It will be better if the matrix with new combination be created at each iteration so that after using it I can discard it or else storing all the combinations is very space intensive. Can anybody help me ?

one possible solution I could think of is to generate all possible combinations of row1, row2, row3 and row4 and create a matrix in each iteration. Does that look feasible?

  • 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-19T23:37:57+00:00Added an answer on May 19, 2026 at 11:37 pm

    Here’s one possible solution. If you ignore the diagonal ones for the moment, you can generate all possible patterns for the other 7 values using the functions KRON, REPMAT, PERMS, UNIQUE, EYE, and ONES:

    >> rowPatterns = [kron(eye(3)-1,ones(4,1)) ...      %# For 2 out of 3 as -1
                      repmat(eye(4),3,1); ...           %# For 1 out of 4 as 1
                      repmat([-1 -1 -1],6,1) ...        %# For 3 out of 3 as -1
                      unique(perms([1 1 0 0]),'rows')]  %# For 2 out of 4 as 1
    
    rowPatterns =
    
         0    -1    -1     1     0     0     0
         0    -1    -1     0     1     0     0
         0    -1    -1     0     0     1     0
         0    -1    -1     0     0     0     1
        -1     0    -1     1     0     0     0
        -1     0    -1     0     1     0     0
        -1     0    -1     0     0     1     0
        -1     0    -1     0     0     0     1
        -1    -1     0     1     0     0     0
        -1    -1     0     0     1     0     0
        -1    -1     0     0     0     1     0
        -1    -1     0     0     0     0     1
        -1    -1    -1     0     0     1     1
        -1    -1    -1     0     1     0     1
        -1    -1    -1     0     1     1     0
        -1    -1    -1     1     0     0     1
        -1    -1    -1     1     0     1     0
        -1    -1    -1     1     1     0     0
    

    Note that this is 18 possible patterns for any given row, so your matrix A can have 18^4 = 104,976 possible row patterns (quite a bit). You can generate every possible 4-wise row pattern index by using the functions NDGRID, CAT, and RESHAPE:

    [indexSets{1:4}] = ndgrid(1:18);
    indexSets = reshape(cat(5,indexSets{:}),[],4);
    

    And indexSets will be a 104,976-by-4 matrix with each row containing one combination of 4 values between 1 and 18, inclusive, to be used as indices into rowPatterns to generate a unique matrix A. Now you can loop over each set of 4-wise row pattern indices and generate the matrix A using the functions TRIL, TRIU, EYE, and ZEROS:

    for iPattern = 1:104976
      A = rowPatterns(indexSets(iPattern,:),:);  %# Get the selected row patterns
      A = [tril(A,-1) zeros(4,1)] + ...          %# Separate the 7-by-4 matrix into
          [zeros(4,1) triu(A)] + ...             %#   lower and upper parts so you
          [eye(4) zeros(4)];                     %#   can insert the diagonal ones
      %# Store A in a variable or perform some computation with it here
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create images like this from a double precision matrix using MATLAB.
I want to create a vector of cv::Matrix in a c++ program and on
i want create Dynamic Slideshow in Jquery i'm Write this code var ctx =
Given I have a matrix 3x3 A of rank 3. I want to create
vector= 3 4 8 5 2 1 6 the matrix i want to create
I want create texture atlas(matrix of images) from multiple images.Is their any applescript that
I want to create a matrix in matlab with 500 cell (50 row,10 column
I want to write a function to create an empty square matrix have size
I want to create class instance inside itself. I tried to it by this
Let's say I want to create an 100x100 matrix of which every row contains

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.