Averaging specific rows and specific columns in N by N matrix

1 回表示 (過去 30 日間)
Abdulhakim Alezzi
Abdulhakim Alezzi 2023 年 1 月 9 日
コメント済み: Mathieu NOE 2023 年 1 月 11 日
hI friends,
I am trying to do averging for specfic rows with specific columns in C=19*19 matrix to have a final matrix of 5*5.
I am using the following code :
Y=mean (C([3:5 10:11 16:17, 12:13 19, 1 7, 2 6 8, 14:15],[3:5 10:11 16:17, 12:13 19, 1 7, 2 6 8, 14:15]));
But the output matrix is 1*17.
Any help will be appreciated.

採用された回答

Mathieu NOE
Mathieu NOE 2023 年 1 月 10 日
hello
you need somehow to split your 5 domains into separate arrays (like a cell array as below)
then you can perform a for loop on each submatrix
try this
C = rand(19,19);
ind = [{[3:5 10:11 16:17]}; {[12:13 19]}; {[1 7]}; {[2 6 8]}; {14:15}];
for ci = 1:numel(ind) % row
for cj = 1:numel(ind) % col
ind_r = ind{ci};
ind_c = ind{cj};
Y(ci,cj)=mean(C(ind_r,ind_c),'all');
end
end
  2 件のコメント
Abdulhakim Alezzi
Abdulhakim Alezzi 2023 年 1 月 10 日
Thank You so much @Mathieu NOE. this is really helping.
Mathieu NOE
Mathieu NOE 2023 年 1 月 11 日
My pleasure !

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by