How to call element from vector out of t = @(theta) x*cos(theta)-y*sin(theta);
조회 수: 4 (최근 30일)
이전 댓글 표시
x = linspace(1,10,10);
y=x;
t = @(theta) x*cos(theta)-y*sin(theta);
t(0.1) will give me vector. How to get element 5 ?
댓글 수: 0
채택된 답변
Star Strider
2015년 3월 13일
My approach:
tv = t(0.1);
t5 = tv(5) % Element 5
댓글 수: 2
Star Strider
2015년 3월 13일
편집: Star Strider
2015년 3월 13일
My pleasure.
Unfortunately, not.
The only way around it is to include ‘x’ and ‘y’ as arguments, then reference the 5th element of each:
txy = @(theta,x,y) x*cos(theta)-y*sin(theta);
t5 = txy(0.1,x(5),y(5))
----------
This strange construction actually works (it creates a cell array, and then references the 5th element and assigns the correct value to t5), but throws an annoying error and halts execution of the script:
t5 = {t(0.1)}(5)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!