I have an array B of :
B=[1 2 3; 10 20 30 ; 100 200 300 ; 1000 2000 3000]
such that
B =
1 2 3
10 20 30
100 200 300
1000 2000 3000
I am using the following code to find the possible combination between these variables that are below a certain value (a constraint) -- 2000 in this case :
A=[123; 323; 12 ; 421]
SA=sum(A)
V=cell(length(B),1);
n=1;
for k = 1:length(B)
for idx = nchoosek(1:length(B), k)'
B_subset = B(idx);
if (SA + sum(B_subset) <= 2000)
V(n)={B_subset(:)}; %store them in a cell
n=n+1;
end
end
end
However I failed to combine them the way I want below.
Objective :
Find the possible combinations from B to be added with SA so that their sum is less than 2000 ?
Constraint 1 :
- Only one value from each row in array
Bcan be used at once.
For example, this is NOT acceptable : [1 2 20] [2 20 30]
This is the correct one : [1 20 100] [3 200 3000]
Constraint 2 : - The answers should be stored in the cell V in only one column (as initialised in the code above).
The cell should have an output similar to the one I'm currently having :
V =
[ 100]
[ 300]
[ 200]
[2x1 double]
[2x1 double]
[2x1 double]
[3x1 double]
VOK? Do you just need output formatting?Vlooks suspiciously familiar :) Will update the answer.