フィルターのクリア

average sections of matrix

11 ビュー (過去 30 日間)
Luke McLellan
Luke McLellan 2018 年 7 月 12 日
コメント済み: Star Strider 2018 年 7 月 17 日
Hi there, I am trying to average sections of a matrix at a time. The matrix is 31x109. Initially I am trying to build another matrix from the average of the first 25 elements increments in the first row, then the second 25(beginning from the the last element in the previous average); this will later be applied to all rows. My current attempt is
for f = 1:[1:25:108]; Ave_PpIX(f,:) = PpIX_Dose_Matrix(1,1:f); end
ave_PpIX = mean(Ave_PpIX);
Am idea of the matrix is: [ave(1-25) ave(13-38) ave(25-50)...]
If anyone has had any previous experience doing this I would really appreciate any help.
Thnaks Luke
  1 件のコメント
Jan
Jan 2018 年 7 月 12 日
Why 108 in the loop, not 109? What should happen with the last chunk, which has less then 25 elements?
1:[a:b:c] is the same as 1:a.

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

採用された回答

Star Strider
Star Strider 2018 年 7 月 12 日
I am not certain that I understand the result you want.
Try this:
M = rand(31, 109); % Original Matrix
Cols = [ones(1, fix(size(M,2)/25))*25 rem(size(M,2),25)]; % Create Column Sub-Sections
C = mat2cell(M, size(M,1), Cols); % Cell Array Of Sub-Sections
Cmean = cellfun(@(x)mean(x,2), C, 'Uni',0); % Row Means For Each Section
Mmean = cell2mat(Cmean); % Convert To Double Matrix Of Row Mean Vectors For Each Sub-Section
  9 件のコメント
Luke McLellan
Luke McLellan 2018 年 7 月 17 日
I do believe that you are my knight in shining algorithm but I will have to return to the code next week now
Star Strider
Star Strider 2018 年 7 月 17 日
Thank you!

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

その他の回答 (1 件)

Jan
Jan 2018 年 7 月 12 日
編集済み: Jan 2018 年 7 月 13 日
PpIX_Dose_Matrix = rand(31, 109);
n = size(PpIX_Dose_Matrix, 2);
k = 0;
for f = 1:24:n
k = k + 1;
Ave_PpIX(k) = mean(PpIX_Dose_Matrix(1, f:f+24));
end
This can fail, when f+25 is outside the existing range. A test with if can catch this:
if f+25 <= n
...
  3 件のコメント
Jan
Jan 2018 年 7 月 13 日
for f = 1:12:n
k = k + 1;
Ave_PpIX(k) = mean(PpIX_Dose_Matrix(1, f:f+24));
end
Luke McLellan
Luke McLellan 2018 年 7 月 16 日
Thanks again for your comments

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by