Arrange average in same vector values

2 ビュー (過去 30 日間)
Daeyeon Koh
Daeyeon Koh 2021 年 10 月 12 日
コメント済み: Mathieu NOE 2021 年 10 月 12 日
I want to find the 1-column average of vectors with the same 2 columns values.
At now, D1 vector array is obtained through my function as shown in the figure, and E1 is obtained in ascending order through indexing.
How can I arrange the average values according to the 2 column values of E1 as shown in the figure?
[a,index1]=sort(D1(:,3));
E1=D1(index1(1:1:end,:),:);
[rowE1,colE1]=size(E1);

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 10 月 12 日
hello
try this
%% dummy data
B = ([1 1 1 1 2 2 2 4 4 4 4 1 1 1 1 2]/8)'; % 2nd column data
A = 100*rand(size(B))'; % first column data
%% main code
Bu = unique(B);
for ci = 1:numel(Bu)
ind = (B == Bu(ci));
A_extract_mean(ci,1) = mean(A(ind));
end
C = [A_extract_mean Bu] % First colums contains average values according to the 2nd column values of E1
  2 件のコメント
Daeyeon Koh
Daeyeon Koh 2021 年 10 月 12 日
It successfully works! thanks a lot.
Mathieu NOE
Mathieu NOE 2021 年 10 月 12 日
My pleasure (as always) !

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by