MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# Thread Subject: Creating a vector by comparing values in two other vectors

 Subject: Creating a vector by comparing values in two other vectors From: Ulrik Nash Date: 3 Sep, 2011 17:41:08 Message: 1 of 2 Hi Everyone, Suppose I have a vector A: A = [0.5;0.5;0.75;0.25] and a vector B B = [0.25;0.75;0.50;0.50] Now I wish to create vector C, which contains r numbers. These r numbers can either be -1 or 1. The criteria for when the value is -1 or 1 is as follows: when a given value in B is larger than the corresponding value in A, then the corresponding value in C is -1, otherwise 1. So, in the example: C = [1;-1;1;-1] What expression can create C? Regards, Ulrik.
 Subject: Creating a vector by comparing values in two other vectors From: dpb Date: 3 Sep, 2011 17:50:00 Message: 2 of 2 On 9/3/2011 12:41 PM, Ulrik Nash wrote: ... > when a given value in B is larger than the corresponding value in A, > then the corresponding value in C is -1, otherwise 1. ... Come on, you're not even trying here... :( W/O being clever at all, C=ones(size(A)); C(B>A)=-1; There are any number of ways to make it work in one step; thinking of one of them is left as "exercise for the student" --