|
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i422qr$7jq$1@fred.mathworks.com>...
> "Michael " <mteo@empiricap.com> wrote in message <i3vv6j$kfu$1@fred.mathworks.com>...
> My guess is that you mean that if a = 1, that puts things in an 'on' mode which causes c to become a 1 and stay that way until a value in b puts it in the 'off' mode by becoming -1. When the latter happens, c will turn to 0 and stay there until a again brings it back to the 'on' mode. Matt has already pointed one weakness. How does it behave when a "wants" an 'on' mode and b an 'off' mode at the same time? Another weakness is, what mode do you wish c to start in initially if both a and b start with 0's?
>
> I will assume that if both a and b contradict each other, then you will leave the mode the way it was. Also it is assumed that initially the mode starts at 'off'.
>
> n = length(a);
> c = zeros(size(a));
> A = a==1;
> B = b~=-1;
> m = false; % Mode is 'off' initially
> for k = 1:n
> m = A(k)&&B(k)||A(k)&&m)||B(k)&&m;
> c(k) = +m;
> end
>
> Roger Stafford
Thanks you pple for helping and clarifying. And special thanks to Roger for the details elaboration.
Q1. How does it behave when a "wants" an 'on' mode and b an 'off' mode at the same time?
A1: The mode will switch. i.e., if previous mode is 'on' and 'a=1' and 'b=-1', c will become 0. Similar, if previous mode is 'off' and 'a=1' and 'b=-1', c will become 1.
Q2. What mode do you wish c to start in initially if both a and b start with 0's?
A2: The mode will always assume to start as '0'. If both a and b start with '0', c will be 0.
The for-loop solution is acceptable but i am looking for a more efficient computation, such as using vectors manipulation.
Thanks, any advices or questions is appreciated.
|