how to extract a column from table ?

3 views (last 30 days)
Hi, I have a table and i would like to create a function that extract a column in which the sum of the elemnts is the highest ; in the following case, for example i have
a b c d
________ ________ ________ ________
3.04 0.2 0.12 0.81
2.24 0.1 0.08 0.47
2.24 0.1 0.08 0.47
2.24 0.1 0.08 0.47
2.24 0.1 0.08 0.47
2.78 0.1 0.08 0.47
2.78 0.1 0.08 0.57
2.78 0.1 0.08 0.57
2.78 0.1 0.08 0.57
3.2 0.1 0.08 0.57
3.2 0.1 0.08 0.57
3.2 0.1 0.08 0.57
3.2 0.1 0.08 0.57
3.2 0.1 0.08 0.57
3.2 0.1 0.08 0.57
3.2 0.1 0.08 0.57
function M=Max(Y)
A = varfun(@sum,Y);
[~,I] = varfun(@max,A)
M=Y(:,I);
But I don't know how to extract maximum and his position

Accepted Answer

David Hill
David Hill on 14 Jan 2020
Not sure why you need a table, but convert to matrix, then:
[~,idx]=max(sum(y));%idx will give you the column number of the max sum.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!