Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Odometer Step Problem

149 views
Skip to first unread message

Ian

unread,
Oct 2, 2008, 1:05:04 PM10/2/08
to
I have the below function used to generate a matrix of values for an odometer step problem. Is there a way to get outputs from 1:MaxVals for the whole problem instead of just MaxVals?

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

Walter Roberson

unread,
Oct 2, 2008, 1:39:18 PM10/2/08
to

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.

Ian

unread,
Oct 2, 2008, 9:55:06 PM10/2/08
to
Walter Roberson <robe...@hushmail.com> wrote in message <BG7Fk.5179$Zf2....@newsfe09.iad>...

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))?

Ian

unread,
Oct 3, 2008, 3:21:02 AM10/3/08
to
Could someone help with the questions? I was wondering what it meant to add a 2nd output to the function and the part about defining A as a cell array rather than a matrix.

Ian

unread,
Oct 3, 2008, 11:42:02 AM10/3/08
to
"Ian " <z06...@ntu.edu.sg> wrote in message <gc4h4u$ef$1...@fred.mathworks.com>...

> Could someone help with the questions? I was wondering what it meant to add a 2nd output to the function and the part about defining A as a cell array rather than a matrix.
Can anyone help with this?

Walter Roberson

unread,
Oct 4, 2008, 2:21:17 AM10/4/08
to

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.

Ian

unread,
Oct 4, 2008, 7:32:01 AM10/4/08
to
Walter Roberson <robe...@hushmail.com> wrote in message <kXDFk.504$kn5...@newsfe12.iad>...
Sorry for posing such an ill-phrased question.

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

Walter Roberson

unread,
Oct 9, 2008, 2:59:55 AM10/9/08
to
Ian wrote:

> 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

0 new messages