calling seperate members of a vector function

3 ビュー (過去 30 日間)
João Teixeira
João Teixeira 2021 年 10 月 25 日
コメント済み: Matt J 2021 年 10 月 28 日
I want to call seperate members of my defined vector function and I don't know how to do it.
For example I defined the vector function as shown:
F=@(x,y,z) [x- y, y^2 , z+2] which shows:
@(x, y, z) [x - y, y ^ 2, z + 2]
how do i call only one member, like the first one "x-y"? Because if I do F(1) I'm defining x as equal to 1.
  1 件のコメント
Ive J
Ive J 2021 年 10 月 25 日
Why not this?
F = @(x) [x(1) - x(2), x(2)^2 , x(3) + 2];
res = F(1:3);
res(1)
ans = -1

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

採用された回答

Matt J
Matt J 2021 年 10 月 26 日
編集済み: Matt J 2021 年 10 月 26 日
There's no way to do that. You could do it if the components are held in struct form, e .g.,
F=@(x,y) struct('a',x-y,'b', y^2);
F(5,3).a
ans = 2
  2 件のコメント
João Teixeira
João Teixeira 2021 年 10 月 28 日
Ok, thanks for your help!
Matt J
Matt J 2021 年 10 月 28 日
You're welcome, but if you consider your question answered, please Accept-click the answer.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by