Multiple function handle in varfun

13 ビュー (過去 30 日間)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 12 月 7 日
コメント済み: Walter Roberson 2020 年 9 月 17 日
I need to calculate the mean and STD of elements of table and the resulting table show me the mean and std in two columns next to each other. Here is the code I am using:
Tmean = varfun(@mean,T,'GroupingVariables',...
{'stor','s_method'},'InputVariables',{'ix','atfa','iss','aad'});
How can I add STD to Tmean? I dont want to make separate table for STD.

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 12 月 7 日
You can use @(v) [mean(v), std(v)] as the function, and splitvars() afterwards.
  2 件のコメント
Yosef Farzi
Yosef Farzi 2020 年 9 月 17 日
That was a smart move. i am trying to save 'mean' string in a variable and the use that variable for splitvars(). no luck so far, any suggestions?
a= mean
b=std
@(v) [a(v),b(v)]
splitvars(T,[a,b])
Walter Roberson
Walter Roberson 2020 年 9 月 17 日
fun = @(v) [feval(a,v), feval(b,v)]
Tmean = varfun(fun, T, 'GroupingVariables', ...
{'stor', 's_method'}, 'InputVariables', {'ix','atfa','iss','aad'});
Tout = splitvars(Tmean)
I would not recommend this approach. You would be better using
afun = str2func(a);
bfun = str2func(b);
fun = @(v) afun(v), bfun(v));

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

カテゴリ

Help Center および File ExchangeDescriptive Statistics and Visualization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by