Cross products with anonymous functions

1 visualizzazione (ultimi 30 giorni)
I please need help with my code. I want to end up with a matrix. I have an anonymous function which I would like to pass various values (in a vector form) and then I want the outputs in a matrix form.
n = 4;
A = @(th) [-R.*cos(th),-R.*sin(th), 0];
theta = 0:pi/2:2*pi;
Lets say I have values for theta of 0:pi/n:2*pi; When I evaluate the function I get this:
u = 1×9
-0.0500 -0.0250 0.0250 0.0500 0 -0.0433 -0.0433 -0.0000 0
I understand that the vector has the answer vectors next to each other, but where are the intermediate 0's? I would expect the answer to have atleast 12 values.
This is so that I could cross product it with other matrices later on.
Any help would be much appreciated!

Risposta accettata

Anton Gribovskiy
Anton Gribovskiy il 23 Set 2019
If you sure that your th will always be 1-by-n vector, you just need to put semicolons instead of comas for vertical cat:
A = @(th) [-R.*cos(th);-R.*sin(th); zeros(1, length(th))];
Or, if you want to make it working for vertical and horizontal vectors
A = @(th) [-R.*cos(th(:).');-R.*sin(th(:).'); zeros(1, length(th))];
  1 Commento
Jonathan Rabe
Jonathan Rabe il 23 Set 2019
Thank you so much! I have been struggling to get this to work for hours now.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by