Averaging data between two integer and corresponding column of a matrix

2 ビュー (過去 30 日間)
Sudhir Rai
Sudhir Rai 2023 年 3 月 21 日
編集済み: Sudhir Rai 2023 年 3 月 23 日
I have this type of matrix
A = [1 2 3 4 5 6; 1.234 1.11 1.3 2.31 2.3 2.4]'
I want to average all data between two integer of 2nd column and corresponding data of firs clumn to form new matrix
  1 件のコメント
Sudhir Rai
Sudhir Rai 2023 年 3 月 23 日
For A = [1 2 3 4 5 6; 1.234 1.11 1.3 2.31 2.3 2.4]'
I need output B= [2 7.5; 1.21 2.33]'
i.e average (1.234 1.11 1.3) and corresponding 1st column average = avg(1 2 3)
(1.234 1.11 1.3) is between 1 & 2
similarly (2.31 2.3 2.4) is between 2&3

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

回答 (1 件)

KSSV
KSSV 2023 年 3 月 21 日
A = [1 2 3 4 5 6; 1.234 1.11 1.3 2.31 2.3 2.4]' ;
idx = fix(A(:,2))==2 ;
mean(A(idx,1))
ans = 5
  1 件のコメント
Sudhir Rai
Sudhir Rai 2023 年 3 月 22 日
編集済み: Sudhir Rai 2023 年 3 月 23 日
This not the out put I want
For A = [1 2 3 4 5 6; 1.234 1.11 1.3 2.31 2.3 2.4]'
I need output B= [2 7.5; 1.21 2.33]'
i.e average (1.234 1.11 1.3) and corresponding 1st column average = avg(1 2 3)
(1.234 1.11 1.3) is between 1 & 2
similarly (2.31 2.3 2.4) is between 2&3

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by