How do I create a function where output S has the rows as input N

I am trying to create a function where the output S shows selected statistics of input N. I need output S to have the same number of rows as input N. The first column of S has to contain the mean values of the corresponding rows in N. (I will add median and minimum values later.)
Right now my result is 2.5 (the mean value of the first row in N). However I want it to keep going and calculate the mean value of row two(5.5), three(9.5) etc.
N =[1 2 3 4;4 5 6 7;8 9 10 11]
my function:
function [S]=simple_stats(N)
S=mean(N(1:1:1,1:1:end));
end
Thank you!

 採用された回答

dpb
dpb 2017 年 2 月 19 日

1 投票

TMW already wrote the function for you...
>> N =[1 2 3 4;4 5 6 7;8 9 10 11];
>> S=mean(N,2)
S =
2.5
5.5
9.5
>>
The various other functions have similar DIM arguments; read the documentation/help.

1 件のコメント

JGraf
JGraf 2017 年 2 月 19 日
Thank you. Much simpler than my code

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

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2017 年 2 月 19 日

コメント済み:

2017 年 2 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by