Matrix calculation indexing conditional

1 Ansicht (letzte 30 Tage)
Zeynab Mousavikhamene
Zeynab Mousavikhamene am 13 Aug. 2019
Kommentiert: Andrei Bobrov am 15 Aug. 2019
I have a matrxi of 500 rows and 6 columns. I need to sum all the rows of 2nd column of the matrix if their 3rd column and 4th coumns equal to specific numbers.
How can I do that?
Lets explain more: One column is the time. An other column is radius. We can have multiple rows of the same time. Or multiple rows that have the same radius. An other coulmn is number of cells. I want to say for all times=2 and all radius=3 sum the number of cells.
  2 Kommentare
darova
darova am 13 Aug. 2019
Do you have any attempts?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 13 Aug. 2019
Bearbeitet: Andrei Bobrov am 13 Aug. 2019
Let A - your array (500 x 6):
T = array2table(A);
T_out = varfun(@sum,T,'InputVariables',2,'GroupingVariables',3:4);
  9 Kommentare
Zeynab Mousavikhamene
Zeynab Mousavikhamene am 14 Aug. 2019
Can you explain more? Because time and radius donot have the same size.
Andrei Bobrov
Andrei Bobrov am 15 Aug. 2019
GroupCount this is numbers of the same rows in the sub-matrix of two columns - [time, radius]

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help 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