MATLAB Answers

Find max value with multiple conditions

30 views (last 30 days)
How can I find max value with 2 or more conditions (such as maxifs in excel).
Thanks before

  6 Comments

Show 3 older comments
Andrei Bobrov
Andrei Bobrov on 16 Jan 2020
Please attach small part of your excel-file or data table as MATLAB variable - 'table' in mat -file.

Sign in to comment.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 16 Jan 2020
T=readtable('wave height data.xlsx');
[r,rn] = findgroups(T(:,1));
[c,cn] = findgroups(T(:,2));
out = accumarray([r,c],T.WaveHeight,[],@max);
Tout = array2table([rn.Year,out],'VariableNames',[{'Year'};cn.Direction]);

  2 Comments

Andrei Bobrov
Andrei Bobrov on 17 Jan 2020
Anita! If my answer solved your problem, then please accept it.

Sign in to comment.

More Answers (1)

CAM
CAM on 16 Jan 2020
Edited: CAM on 16 Jan 2020
Use logic statements for each criterion. Use logical "AND" (&) to see which elements meet all criteria. Find the max of those values.
Air Code (untested):
idxC1 = (matrix > criterion1);
idxC2 = (matrix < criterion2);
...
idxOverall = idxC1 & idxC2 & ... & idxCn;
MaxVal = max(matrix(idxOverall));

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!