find the difference between two vectors in each value in matlab

To find the difference between two vectors in each value in Matlab, you can use the following code:

main.m
vector1 = [1, 2, 3];
vector2 = [4, 5, 6];
difference = vector2 - vector1;
74 chars
4 lines

In this example, we have two vectors vector1 and vector2. The difference variable will contain the element-wise difference of the two input vectors.

Alternatively, you can use the minus function to achieve the same result:

main.m
difference = minus(vector2, vector1);
38 chars
2 lines

Either way, the resulting difference variable will be:

main.m
difference = 

     3     3     3
34 chars
4 lines

This indicates that the difference between the first elements of vector1 and vector2 is 3, the difference between the second elements is 3, and the difference between the third elements is 3.

related categories

gistlibby LogSnag