Cross products with anonymous functions

1 回表示 (過去 30 日間)
Jonathan Rabe
Jonathan Rabe 2019 年 9 月 23 日
コメント済み: Jonathan Rabe 2019 年 9 月 23 日
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!

採用された回答

Anton Gribovskiy
Anton Gribovskiy 2019 年 9 月 23 日
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 件のコメント
Jonathan Rabe
Jonathan Rabe 2019 年 9 月 23 日
Thank you so much! I have been struggling to get this to work for hours now.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by