Matlab Arrays

Thread Starter

monkles

Joined Aug 6, 2009
9
Hey guys,

I'm trying to create my own median filter without having to use the medfilt function in Matlab. I need to:
loop through matrix entries from 1-1000(for instance)
I need it to grab entries 1-5 and store the values in an array or something
I need it to then calculate the median of those five entries and store them in a new matrix in the first slot.
Then it needs to go back and grab entries 2-6, store them in the array, calculate the median and place the answer in the new matrix in the second slot and so on.
My only problem really is I don't know how to create a temporary array to hold the five values(that I need to calculate the median of).
Any help is greatly appreciated.
 

johndoe45

Joined Jan 30, 2010
364
if want function file (file name must be same as function)
in this case the filename must be medfilt.m

function [array,med]=medfilt(y,x)

i=1;

for i=1:length(y)-4

med(i)=median(y(i:4+i));
array(i,x)=y(i:4+i);
i=i+1;

end

then make blank m-file

y=rand(1,10);
x=1:5;

[array,median]=medfilt(y,x)

run file
 
Top