Anonymous function only returns single answer

I have a function where its inputs are two arrays. How do I get the function to return an array of values rather than one single value? The value returned for b is -5.6e-4. Thanks
Code shown here:
x=pi:pi/100:2*pi;
y=x.^2;
z = @(a,b) ((sin(a)+cos(b))/((a.^2)+(b.^2)));
b = z(x,y);

 採用された回答

Matt J
Matt J 2023 年 3 月 21 日
編集済み: Matt J 2023 年 3 月 21 日

1 投票

Use the elementwise division operator ./
x=pi:pi/100:2*pi;
y=x.^2;
z = @(a,b) ((sin(a)+cos(b))./((a.^2)+(b.^2)));
b = z(x,y)
b = 1×101
-0.0084 -0.0075 -0.0063 -0.0050 -0.0035 -0.0021 -0.0007 0.0006 0.0017 0.0026 0.0033 0.0036 0.0037 0.0035 0.0030 0.0023 0.0014 0.0004 -0.0007 -0.0019 -0.0031 -0.0041 -0.0050 -0.0058 -0.0063 -0.0066 -0.0066 -0.0064 -0.0060 -0.0054

2 件のコメント

Alexander
Alexander 2023 年 3 月 22 日
Perfect thank you
Matt J
Matt J 2023 年 3 月 22 日
You're quite welcome, but please Accept-click the answer to indicate that your question is resolved.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2023 年 3 月 21 日

コメント済み:

2023 年 3 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by