MATLAB Answers

# two conditions on two 8*256 matrices

1 view (last 30 days)
Nabil Mederbel on 13 Apr 2019
Answered: Matt J on 13 Apr 2019
Hi everyone,
i have problem about knapsack problem.
8*256 matrix A contains element representing the weigth
8*256 matrix B containg elements representing the value .
i want to get the max value with a weight constrains not excceding 28.
below line of code retund a lot value ?
indices = find((A(:,1)<capacity) & y(:,1)== max(valid_benefit_ar))
##### 2 CommentsShowHide 1 older comment
Nabil Mederbel on 13 Apr 2019
W = [ 1 3 4] && weight
b = [ 5 6 7] && value
n = 8 %% possible combonation
capacity = 7 && masse in Kg
indices = find((W(:,1)<capacity) & y(:,1)== max(sum b))

Sign in to comment.

### Answers (2)

Nabil Mederbel on 13 Apr 2019 ##### 1 CommentShowHide None
Nabil Mederbel on 13 Apr 2019
hello, I want to optimisa the code by combining the two condition maximum value with weight constraint usng
indices = find((W(:,1)<capacity) & y(:,1)== max(sum b))
and then retund row value

Sign in to comment.

Matt J on 13 Apr 2019
There are lots of knapsack problem solvers on the File Exchange
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!