Matrix addition and means
9 views (last 30 days)
I am trying to take a matrix of any size , whether it has one row or 9, and write a function file that add the each element by its immediate neighbor then average it and replace. So if
the function would produce
1.5 1 1 .5
here is what I have so far, but for some reason it wont add the edges.
function [ b] = Avg_Num(a )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
if (r*c) == 1
elseif r ==1
for j= 2:(c-1)
elseif r >1
for i=2 :(r-1)
Image Analyst on 11 Apr 2014
Edited: Image Analyst on 11 Apr 2014
Wow. How would you like to do all that in a single line? If so, how about using convolution:
% First with a 1D "a"
output = conv2(a, [1, 1]/2, 'same')
% Now with a 2D "a" - use a 3 by 3 array to do the scanning.
windowSize = 3
a = magic(windowSize); % Sample data
output = conv2(a, [windowSize, windowSize]/windowSize^2, 'same')