function A = odoprob(array_info,MaxVals)
if length(array_info) > 1
array_infot = array_info(1:end-1);
A = [];
for k = max(MaxVals-sum(array_infot),0):min(MaxVals,array_info(end))
B = odoprob(array_infot,MaxVals-k);
A = [A;B,repmat(k,size(B,1),1)];
end
else
A = MaxVals;
end
Your routine is recursive, so if you were to change the output A then your
routine would stop working, it appears to me.
You could add a second output to odoprob that accumulated whatever results
you want. As A's will be of different sizes as you go, you would probably
want the new value to be a cell array instead of a plain matrix.
Thanks for replying Walter!
Just to clarify, I should changes lines 5, 7 and 10 in the code or just line 1?
And what do you mean by using a cell array instead, do you mean to change line 5 to A = cell(size(array_info))?
Your original question is ill-posed. What output exactly do you want?
An example please, complete with (short) realistic input so that we can
do test runs.
Say for odoprob([3;3;3;3;1;1;1],2)
ans =
2 0 0 0 0 0 0
1 1 0 0 0 0 0
0 2 0 0 0 0 0
1 0 1 0 0 0 0
0 1 1 0 0 0 0
0 0 2 0 0 0 0
1 0 0 1 0 0 0
0 1 0 1 0 0 0
0 0 1 1 0 0 0
0 0 0 2 0 0 0
1 0 0 0 1 0 0
0 1 0 0 1 0 0
0 0 1 0 1 0 0
0 0 0 1 1 0 0
1 0 0 0 0 1 0
0 1 0 0 0 1 0
0 0 1 0 0 1 0
0 0 0 1 0 1 0
0 0 0 0 1 1 0
1 0 0 0 0 0 1
0 1 0 0 0 0 1
0 0 1 0 0 0 1
0 0 0 1 0 0 1
0 0 0 0 1 0 1
0 0 0 0 0 1 1
What I would like to also have in the output are the possibilities of the following:
0 0 0 0 0 0 0
1 0 0 0 0 0 0
0 1 0 0 0 0 0
> Say for odoprob([3;3;3;3;1;1;1],2)
> ans =
> 2 0 0 0 0 0 0
> 1 1 0 0 0 0 0
[etc]
> What I would like to also have in the output are the possibilities of the following:
> 0 0 0 0 0 0 0
> 1 0 0 0 0 0 0
> 0 1 0 0 0 0 0
So what you want is to include the solutions for all of the similar problems where
the row sum can be from 0 up to the value given by your second parameter. I
decidedly did not get that requirement out of your earlier questions!!
The modified code to do the sub-problems at the same time is:
function A = odoprob(array_info,MaxVals)
if length(array_info) > 1
array_infot = array_info(1:end-1);
A = [];
for k = 0:array_info(end) %changed line
B = odoprob(array_infot,MaxVals-k);
A = [A;B,repmat(k,size(B,1),1)];
end
else
A = (0 : min(MaxVals, array_info)).'; %changed line
end