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

4 visualizaciones (últimos 30 días)
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 comentario
Jamie Hetherington
Jamie Hetherington el 8 de Oct. de 2017
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);

Iniciar sesión para comentar.

Respuestas (1)

Francesco Onorati
Francesco Onorati el 7 de Jul. de 2020
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));

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by