varfun question - How to create function handles and obtain function outputs

4 ビュー (過去 30 日間)
Jamie Hetherington
Jamie Hetherington 2017 年 10 月 8 日
回答済み: Francesco Onorati 2020 年 7 月 7 日
Hi all,
I am having trouble creating a function to be used on tables using the varfun function. I can obtain the min and max on the variables in a table (101x9 table) using the below code. However the main issue is I would also like to output the index at which these points occur and i can't figure out a way to implement the min or max function which gives you the output as well as index e.g. [M,I] = min(x).
I know you can get summary table information but I would like the index as well so I can calculate where this min or max occurs in the normalised data variables.
Any suggestions on if this is possible and if so how to do it would be greatly appreciated!
Thanks in advance
Jamie
%Find min and max of variables in table - Would like to also find index of these outputs
FindMin = @(x)(min(x));
FindMax = @(x)(max(x));
AllMin = varfun(FindMin,NormData);
AllMax = varfun(FindMax,NormData);
  1 件のコメント
Jamie Hetherington
Jamie Hetherington 2017 年 10 月 8 日
I have since simplified the previous code to what you see below, however still can't find a way to obtain index of each of the outputs. The below code put the min and max neatly next to each other in a table so wondering how its possible to write the indexing components into this anonymous function "FindMinMax"? If its even possible.
FindMinMax = @(x)[min(x),max(x)];
AAA = varfun(FindMinMax,NormData);

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

回答 (1 件)

Francesco Onorati
Francesco Onorati 2020 年 7 月 7 日
You can create a small function you can use in your function handle
function i = index_max_handle(x)
[~, i] = max(x);
end
Then
FindMax_ind = @(x)(index_max_handle(x));

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by