How to do computation in local function?

4 ビュー (過去 30 日間)
Sam Yeoh
Sam Yeoh 2022 年 2 月 16 日
コメント済み: Jan 2022 年 2 月 16 日
function [a,b] = c(d,e)
a = d+e;
b = d.*e;
The following MATLAB script utilizes a local function and the c function mentioned above. Compute the final value of vector a. Please show how you obtained your answer. Could someone explain it how to get a briefly? Thank you in advance.
a = [1 2];
a = compute(a);
function a = compute(b)
[a,b] = c(b,b);
end
  3 件のコメント
Sam Yeoh
Sam Yeoh 2022 年 2 月 16 日
I would like to determine final value of vector a.
Geoff Hayes
Geoff Hayes 2022 年 2 月 16 日
Isn't "the final value of a" the output of the compute function?

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

回答 (1 件)

Image Analyst
Image Analyst 2022 年 2 月 16 日
a = [1 2];
a = compute(a)
a = 1×2
2 4
function a = compute(b)
[a,b] = c(b,b);
end
function [a,b] = c(d,e)
a = d+e;
b = d.*e;
end
Not sure what you consider the "final value of a". Do you mean a(end), which would be 4?
  2 件のコメント
Sam Yeoh
Sam Yeoh 2022 年 2 月 16 日
May I ask why multiply it by 2?
Jan
Jan 2022 年 2 月 16 日
@Sam Yeoh: I do not see a multiplication by 2. Do you mean the output "1x2"? This means, that a is an array with the dimensions [1, 2]: One row, 2 columns.

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

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by