Find equal elements in an array and average the corresponding values

1 回表示 (過去 30 日間)
Riccardo Rossi
Riccardo Rossi 2020 年 10 月 12 日
コメント済み: Riccardo Rossi 2020 年 10 月 12 日
Hello, I have a cell array A{2, 6} like the following
[-0.27,11.53,-2.82] [0.01,11.72,-3.27] [-0.04,11.56,-2.87] [-0.01,11.73,-2.62] [-0.01,11.73,-2.62] [0.10,11.58,-3.22]
128151x3 double 55009x3 double 84858x3 double 92417x3 double 40318x3 double 65249x3 double
and I would like to average the values ​​of A{2, x} if 2 or more cells in A {1, x} are equal. Based on the example above I would like to have a cell array A{2, 5} like the following:
[-0.27,11.53,-2.82] [0.01,11.72,-3.27] [-0.04,11.56,-2.87] [-0.01,11.73,-2.62] [0.10,11.58,-3.22]
128151x3 double 55009x3 double 84858x3 double mean (92417x3 double,40318x3 double) 65249x3 double
How can I do it. Thank you very much!
  2 件のコメント
KSSV
KSSV 2020 年 10 月 12 日
You have three columns in each cell. Are the three columns independent or they are (x,y,z)?
Riccardo Rossi
Riccardo Rossi 2020 年 10 月 12 日
Thank you for your answer. They are x,y and z.

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

回答 (1 件)

KSSV
KSSV 2020 年 10 月 12 日
編集済み: KSSV 2020 年 10 月 12 日
Let A and B be your matrices of size 92417x3, 40318x3 respectively. First you need to get them to the same dimension to find the mean. For this, you have to do interpolation.
B_new = A ;
B_new(:,3) = scatteredinterpolant(B(:,1),B(:,2),B(:,3),A(:,1),A(:,2)) ;
themean = B ;
themean(:,3) = (A(:,3)+B(:,3))/2 ;
  3 件のコメント
KSSV
KSSV 2020 年 10 月 12 日
That can be done with ease...you want to find mean..if the first and last point matches??
Riccardo Rossi
Riccardo Rossi 2020 年 10 月 12 日
I want to find the mean of the values in the "second row" if two or more point of the "first row" are equal

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by