varfun question - How to create function handles and obtain function outputs
Mostrar comentarios más antiguos
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
el 8 de Oct. de 2017
Respuestas (1)
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 Tables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!