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

5 次查看(过去 30 天)
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
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 CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by