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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:54:47+00:00 2026-06-15T09:54:47+00:00

We have a MxN matrix and a constrain cstrn = 100; . The constrain

  • 0

We have a MxN matrix and a constrain cstrn = 100;.

The constrain is the summarize limit of column’s elements (per column):

sum(matrix(:,:))<=cstrn.

For a given example as the following:

Columns 1 to 5:
  15  18  -5 22 19
  50  98 -15 39 -8
  70 -15  80 45 38
  31  52   9 80 72
  -2  63  52 71  6
   7  99  32 58 41 

I want to find the max number of element per column who fulfill this constrain.

How can i summarize every column element with the others elements in same column and find which sum combinations uses the max number of elements per column?

In the given example solution is:

   4  3  5  2  5

where

column 1: 15 + 50 + 31 +7 +(-2)

column 2: 18 +(-15) + 52 or 63 etc.

Thank you in advance.

  • 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-15T09:54:48+00:00Added an answer on June 15, 2026 at 9:54 am

    Since it is always easier to fit small elements into a sum, you can do a sort, followed by the cumulative sum:

    m= [
      15  18  -5 22 19
      50  98 -15 39 -8
      70 -15  80 45 38
      31  52   9 80 72
      -2  63  52 71  6
       7  99  32 58 41]; 
    
    cs = cumsum(sort(m))
    cs =
        -2   -15   -15    22    -8
         5     3   -20    61    -2
        20    55   -11   106    17
        51   118    21   164    55
       101   216    73   235    96
       171   315   153   315   168
    

    Now you easily identify at which element you cross the threshold cnstrn (thanks, @sevenless)!

    out = sum(cs <= cnstrn)
    
    out =
         4     3     5     2     5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using matplotlib and Python 2.7 I have a MxN matrix of tuples, an
I have an MxN matrix, Z, and some variable h. This matrix represents the
Say I have a matrix ( MxN ) which has its rows and columns
I have a MxN Matrix and would like to convert into a vector MNx1
This is an easy question but say I have an MxN matrix. All I
I have a matrix A of size mXn and I would like to set
I have an mXn matrix of integers. I want to write the matrix to
I have a large mxn matrix, and I have identified the linearly dependent columns.
Say I have a 1D array converted from a MxN 2D matrix, and I
I'd like to multiply a random number vector PT(n)=rand(1,n) by a matrix M(mxn) but

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.