Matlab Arrays

Discussion in 'Programmer's Corner' started by monkles, Mar 19, 2010.

  1. monkles

    Thread Starter New Member

    Aug 6, 2009
    9
    0
    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.
     
  2. johndoe45

    Member

    Jan 30, 2010
    364
    1
    deleted. Go to next one down
     
    Last edited: Mar 20, 2010
  3. johndoe45

    Member

    Jan 30, 2010
    364
    1
    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
     
Loading...