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

6 Kommentare

darova
darova am 15 Jan. 2020
You should attach more details, example
Mohammad Sami
Mohammad Sami am 16 Jan. 2020
If your data is table, create a grouping variable in your data. Then use the function groupsummary.
Anita Fitriani
Anita Fitriani am 16 Jan. 2020
Oh Im sorry for that. So I have data table of wave height. First data is year, the 2nd one is wave height, and the last one is direction. Then, I want to find the maximum of wave height but with spesific year and specific direction. Example, I would find the max of wave height in 2008 from North. If we use excel for this, we could use MAXIFS. And the result that I mean attached as picture here.
Anita Fitriani
Anita Fitriani am 16 Jan. 2020
Andrei Bobrov
Andrei Bobrov am 16 Jan. 2020
Please attach small part of your excel-file or data table as MATLAB variable - 'table' in mat -file.
Anita Fitriani
Anita Fitriani am 16 Jan. 2020
This is small part of my wave height data

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 16 Jan. 2020

1 Stimme

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]);

3 Kommentare

Anita Fitriani
Anita Fitriani am 17 Jan. 2020
Bearbeitet: Anita Fitriani am 17 Jan. 2020
Thankyou so much. It works!
Andrei Bobrov
Andrei Bobrov am 17 Jan. 2020
Anita! If my answer solved your problem, then please accept it.
How do i obtain and tabulate the maximum wave height. Add to that table two separate columns that show the direction and period of each of those yearly maximum wave heights. for 30 years?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

CAM
CAM am 16 Jan. 2020
Bearbeitet: CAM am 16 Jan. 2020

0 Stimmen

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));

Kategorien

Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by