Function writing for variable matrix

1 回表示 (過去 30 日間)
Cside
Cside 2020 年 10 月 3 日
コメント済み: Cside 2020 年 10 月 3 日
Hi i currently have this code and would like to write a function for it. I have to run this function with matrixes labelled A to D. How can I write for this function such that when I input A, B or C at that position, it would give me agem and agestd for the matrix entered?
Thank you!
agem = mean(A(:,6));
agestd = std(A(:,6));
function [agem,agestd]

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 10 月 3 日
編集済み: KALYAN ACHARJYA 2020 年 10 月 3 日
" write for this function such that when I input A, B or C at that position"
Please note: In the function defination, only A is there
function [agem,agestd]=fun1(A)
agem = mean(A(:,6));
agestd = std(A(:,6));
end
Steps:
  1. Save this function as fun1.m file in separate MATLAB file.
  2. Once required, call the function from the mainn code or command widow with passing appropriate A vector data.
From the command window, you can verify the same
>> mat=magic(6);
>> [agem,agested]=fun11(mat)
agem =
18.5000
agested =
5.4681
>>
  1 件のコメント
Cside
Cside 2020 年 10 月 3 日
thank you for being so clear! works perfectly

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by