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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:04:18+00:00 2026-06-17T11:04:18+00:00

I want to construct a binary(0s and 1s) matrix satisfying the following constraints: Each

  • 0

I want to construct a binary(0s and 1s) matrix satisfying the following constraints:

  1. Each column must contains only single binary 1 and rest elements of that column are 0s.

  2. The sum of each ROW of matrix should be a desired value.
    For example, given a rowSum vector of [5 7 6 8 …….] then the sum of first row should be 5, sum of second row should be 7 and so on.

  3. nCol==Sum(rowSum)

Moreover, I would like to consider several (e.g., 7) matrices satisfying the same conditions.

EDIT:
I have tried to write the code and completed the one part of it. The code is:

x=rand(21,50,7);
for k=1:7
    cons=max(x(:,:,7));
    for i=1:50
        for j=1:21
            if x(j,i,k)==cons(i)
                x(j,i,k)=1;
            else
                x(j,i,k)=0;
            end
        end
     end
 end
 x
  • 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-17T11:04:19+00:00Added an answer on June 17, 2026 at 11:04 am

    It would not always be possible to construct a binary matrix that satisfies your requirements.
    Suppose you want a binary matrix of size nRowsxnCols with rowSum (a vector of length nRows) rowSum(k) the number of 1s in kth row.
    So, if nCol ~= sum( rowSum ) it would be impossible to construct such matrix: you would either have columns with no 1s, or columns with too many 1s…

    Therefore, your binary matrix is completely defined through rowSum – up to random permutation of its columns.

    How about this function to construct the basic matrix b:

    function b = makeBizarreBinaryMatrix( rowSum )
    
    nRows = numel( rowSum );
    nCols = sum( rowSum );   
    rows = 1:nRows;
    rowInd = zeros( 1, nCols );
    rowInd( cumsum( [1 rowSum(1:end-1)] ) ) = 1;
    rowInd = rows( cumsum( rowInd ) );
    b = sparse( rowInd, 1:nCols, 1, nRows, nCols );
    

    Now you can use randperm to randomly permute the order of the columns:

    nb = b(:, randperm(size(b,2)) );
    

    Good luck with your thesis.

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

Sidebar

Related Questions

I want to construct a context menu with a menu item for selecting a
I want to construct a string with an array of objects for (int n=0;
In a Windows batch file, I want to construct a classpath of .jar files
i want to realize a construct in MS SQL that would look like this
I want to use the DbProvider class to construct a generic DAL component. This
I want to construct a SELECT statement with a conditional IF. Like, IF there
I want to construct a macro that, given a symbol 'foo , creates a
I want to construct a system which is responsible for updating my database columns.
I want to construct a statement containing and and multiple or expressions in xml
I'm trying to construct a binary tree (unbalanced), given its traversals. I'm currently doing

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.