HOW TO TAKE AVERAGE OF ROW AND COLUMN AT SOME POINT
Show older comments
I HAVE A MATRIX
2 5 3 500 4 5,
3 4 2 2 3 5,
4 5 5 1 2 2
code must scan first where 500 exists and take average of that row and column wher 500 exists excluding that 500,
here ans should be like avg row at first 2+5+3+4+5/5 and avg col of that point 2+1/2,
3 Comments
per isakson
on 24 Aug 2016
I assume you mean
M = [ 2 5 3 500 4 5; 3 4 2 2 3 5; 4 5 5 1 2 2 ];
>> whos M
Name Size Bytes Class Attributes
M 3x6 144 double
abdul wahab aziz
on 24 Aug 2016
abdul wahab aziz
on 24 Aug 2016
Accepted Answer
More Answers (1)
A = [2 5 3 500 4 5; 3 4 2 2 3 5; 4 5 5 1 2 2];
[i, j] = ind2sub(size(A), find(A==500));
m1 = mean(A(i, ~ismember(1:size(A,2), j)));
m2 = mean(A(~ismember(1:size(A,1), i), j));
A(i,j) = (m1 + m2)/2;
or
idx = A == 500
A(idx) = nan;
A(idx) = mean([nanmean(A(:, any(idx, 1))) nanmean(A(any(idx, 2), :), 2)])
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!