필터 지우기
필터 지우기

Cross products with anonymous functions

조회 수: 2 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by