matlabvectorgeometrycoordinatescross-product# Cross product of 2d vectors

I have two coordinate vectors:

```
coor1 = [4 2];
coor2 = [4.3589 1];
```

and I want to find the angle of the rotation, where mathematically it is given by the equation:

where the numerator is the cross product between the two coordinate pairs and the denominator is the dot product.

The problem is that in MATLAB, a cross product isn't possible with 2-element vectors. Running the following code:

```
ang = atan2(norm(cross(coor1,coor2)),dot(coor1,coor2));
```

produces this error:

```
Error using cross
A and B must be of length 3 in the dimension in which the cross product is taken.
```

Is there any way to make `cross`

work? Working this out by hand, the angle of the rotation of both coordinate should be `13.6441`

.

Solution

Why not use the inverse cosine (arccos) instead?

```
coor1 = [4 2];
coor2 = [4.3589 1];
% normalize the vectors:
d1 = coor1 ./ norm(coor1);
d2 = coor2 ./ norm(coor2);
ang = acosd(dot(d1,d2));
```

- Change color of a part of string in MATLAB
- How to execute .m files in Octave
- Return the maximum value of every subgroup in a table
- How can I reformat code in MATLAB editor?
- Create blockwise shifted sparse matrix in matlab directly
- ms-coherence in matlab and python
- MATLAB: Using ODE solvers?
- 'Invalid operator' error when running MATLAB script without changing working directory
- quad function to work in a loop without calling to file
- Integration via trapezoidal sums in MATLAB
- How to solve integral in Matlab having an upper limit set as the sine function?
- Obtaining the constant that makes the integral equal to zero in Matlab
- Code wont produce the value of a definite integral in MATLAB
- CT projection (distance-driven) operator implementation?
- "Array indices must be positive integers or logical values"
- How do I mark (or) shade the area below the graph of Surface plot in Matlab?
- How do I add each frame back together after spectral subtraction (MATLAB)?
- Spectrum Derivative in MATLAB, the end point problem
- implementation of Lomb-Scargle periodogram
- Rectangular Nesting - Convergence to optimal solution using Simulated Annealing
- Parfor for Python
- How to replace NaN from armadillo matrix?
- Clarifying the Process of Generating iid Gaussian Random Vectors in MATLAB
- Fastest way to do repeated element wise matrix multiplication in MATLAB?
- Multiple date formats in MATLAB
- Extract .mat data without matlab - tried scilab unsuccessfully
- How to get recursion coefficients for a Chebychev filter in Matlab
- MATLAB - Stuck on changing x axis for boxplot
- Convert matlab.double array to python array
- Histogram with a mean line in same spot