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 件のコメント

darova
darova 2019 年 8 月 13 日
Do you have any attempts?
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 8 月 13 日
No

サインインしてコメントする。

 採用された回答

Andrei Bobrov
Andrei Bobrov 2019 年 8 月 13 日
編集済み: Andrei Bobrov 2019 年 8 月 13 日

0 投票

Let A - your array (500 x 6):
T = array2table(A);
T_out = varfun(@sum,T,'InputVariables',2,'GroupingVariables',3:4);

9 件のコメント

Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 8 月 13 日
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.
Andrei Bobrov
Andrei Bobrov 2019 年 8 月 13 日
編集済み: Andrei Bobrov 2019 年 8 月 13 日
Please attach small part of your data and result for this part.
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 8 月 13 日
Capture.JPG
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 8 月 13 日
I want to sum the cell_count for specific time and specific radius. Time is: 1,2,3,4,5,6 and radius is: 1,2,3,4,5
Andrei Bobrov
Andrei Bobrov 2019 年 8 月 14 日
T_out = varfun(@sum,T,'GroupingVariables',...
{'time','radius'},'InputVariables','cell_count');
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 8 月 14 日
Thanks for the help. T_out is like this:
Capture.JPG what is the GroupCount column?
Andrei Bobrov
Andrei Bobrov 2019 年 8 月 14 日
編集済み: Andrei Bobrov 2019 年 8 月 14 日
GroupCount this is number of rows - ['time', 'radius'].
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 8 月 14 日
Can you explain more? Because time and radius donot have the same size.
Andrei Bobrov
Andrei Bobrov 2019 年 8 月 15 日
GroupCount this is numbers of the same rows in the sub-matrix of two columns - [time, radius]

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by