|
Walter Roberson <roberson@hushmail.com> wrote in message <ho6t72$k3i$1@canopus.cc.umanitoba.ca>...
> Ambiguous. Suppose you had [9 10 11]. Then subtracting 10 from the
> elements > 9 would give [9 0 1]. Adding 1 to the previous value in the
> row would give [10 1 0], or alternately with your specification could
> give [10 11 0]. The ambiguity is that when you say "previous value in
> the row", you might mean "the value at the previous index location after
> the subtractions have been done", but since you did not specify
> sequential processing, it would be equally valid to hold on to the
> original value at that index location and increment that.
>
> Also, what should be done if the element > 9 occurs in the first position?
>
> And is it really okay that a value could end up at 10 -- e.g., in your
> example, you have 9 14 so the 9 would be incremented to 10 and the 14
> would go to 4. Is that right, or should it trickle left so that the [5 9
> 14] would go to [6 0 4], leaving no value > 9 ?
>
>
> Sequential code:
>
> T = A>9;
> A(T) = A(T) - 10;
> A([T(2:end) false]) = A([T(2:end) false])+ 1;
>
>
> Alternative code permitted by specification:
>
> A([find(A>9) find(A(2:end)>9]) = [A(A>9)-10 A(A(2:end)>9) + 1];
Sorry for the ambiguity, firstly yes I did mean "the value at the previous index location after the subtractions have been done". And yes it should trickle left leaving no value > 9, if a value >9 occurs in the first position then, 10 should be subtracted from it, the whole row vector should be shifted right by 1, essentially adding an extra column, leaving the value in the first position as 1.
For Example:
[9 11 2 3 4] would become
[1 0 1 2 3 4]
or [11 12 5 13 7] would become
[1 2 2 6 3 7]
So the sequential code you provided is correct, it just doesn't account for the first value being >9 as i would like it to. Could it be adjusted at all?
Thanks for your help
|