How to call element from vector out of t = @(theta) x*cos(thet​a)-y*sin(t​heta);

1 回表示 (過去 30 日間)
Ole
Ole 2015 年 3 月 13 日
編集済み: Star Strider 2015 年 3 月 13 日
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 ?

採用された回答

Star Strider
Star Strider 2015 年 3 月 13 日
My approach:
tv = t(0.1);
t5 = tv(5) % Element 5
  2 件のコメント
Ole
Ole 2015 年 3 月 13 日
編集済み: Ole 2015 年 3 月 13 日
Thanks. I was hoping theres some trick without the need of allocating it again t(0.1)(5) .
Star Strider
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 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