フィルターのクリア

Matrix number of rows reduction to a smaller number of rows.

2 ビュー (過去 30 日間)
Pappu Murthy
Pappu Murthy 2018 年 5 月 24 日
編集済み: Stephen23 2018 年 5 月 25 日
I have a matrix for example Nrow, by 6 let us say. The first column has numbers 1 thru n which is less than Nrow.. so some rows have same number in column 1. for example the number 3 may be occurring three times and number 4, 4 times etc. I have to reduce the matrix rows from Nrow to n... the rows which have same column 1 number have to be replace by one row which is is a mean of all rows with same number. for e.g. row with column number 3 could be like this
3, 1, 1, 2, 4, 5, 6
3, 4, 5, 6, 2, 5, 6
3, 2, 3, 5, 6, 3, 7
so we have three rows with same column 1 that is 3. so I replace these three rows with one row; 3, mean of all three rows. So basically i squeeze the Matrix of [Nrow, 6] to a matrix of [n, 6]; How do I do this?
Thanks in advance.
  2 件のコメント
Majid Farzaneh
Majid Farzaneh 2018 年 5 月 24 日
編集済み: Majid Farzaneh 2018 年 5 月 24 日
Hi. I'm not completely sure about my understanding. Is this a correct example for your problem???
Input=
3 1 1 2 4 5 6
3 4 5 6 2 5 6
3 2 3 5 6 3 7
Output =
3 2.3333 3.0000 4.3333 4.0000 4.3333 6.3333
Which 2.3333 is mean of 1,4,2 (column 2) and 3.000 is mean of 1,5,3 (column 3) etc.
Pappu Murthy
Pappu Murthy 2018 年 5 月 25 日
that is correct. the three rows now reduce to just one row with column 1 entry being now 3.

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

採用された回答

Majid Farzaneh
Majid Farzaneh 2018 年 5 月 24 日
編集済み: Majid Farzaneh 2018 年 5 月 24 日
Use this:
% A is your input matrix and B is squeezed matrix
for i=1:n
idx=find(i==A(:,1));
B(i,:)=mean(A(idx,:),1);
end
  2 件のコメント
Pappu Murthy
Pappu Murthy 2018 年 5 月 25 日
That worked like charm. Thanks.
Majid Farzaneh
Majid Farzaneh 2018 年 5 月 25 日
:)) You're welcome.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by