MATLAB Problem

I have a 400 by 640 matrix of ones and zeros. The zeros are near each other and I want to know if there is a function by which i can find the index of the middlemost zero in each column.

For example if in the first column, the entries are
1
1
1
0
0
0
0
0
1
1
the middlemost zero is in the 6th row and i want to get the number 6. please help me with this.

Replies

  • Predictor
    Predictor
    sindhya
    I have a 400 by 640 matrix of ones and zeros. The zeros are near each other and I want to know if there is a function by which i can find the index of the middlemost zero in each column.

    For example if in the first column, the entries are
    1
    1
    1
    0
    0
    0
    0
    0
    1
    1
    the middlemost zero is in the 6th row and i want to get the number 6. please help me with this.

    For each column:

    S =

    1
    1
    1
    0
    0
    0
    0
    0
    1
    1

    >> find(S == 0)

    ans =

    4
    5
    6
    7
    8

    >> median(find(S == 0))

    ans =

    6

    Note that if there are an even number of zeros, the median will include a fractional part, 0.5. Use round, ceil, etc. to fix this.


    -Will Dwinnell
    Data Mining in MATLAB
  • silverscorpion
    silverscorpion
    The above method is correct.
    Btw, it should be noted that it will only work if all the zeros occur continuously, and they occur in the middle of the sequence.
  • Predictor
    Predictor
    silverscorpion
    The above method is correct.
    Btw, it should be noted that it will only work if all the zeros occur continuously, ...
    Yes, although I assumed this was the case, given this phrase in the original post: The zeros are near each other


    silverscorpion
    ... and they occur in the middle of the sequence.
    I don't believe that this is a necessary condition for my suggestion to work:

    S =

    0
    0
    0
    0
    0
    1
    1
    1
    1
    1

    >> median(find(S == 0))

    ans =

    3


    -Will Dwinnell
    Data Mining in MATLAB

You are reading an archived discussion.

Related Posts

hey can anyone add 2 positive integers without using any arithmetic operators. no use of even shift operators. ๐Ÿ˜•๐Ÿ˜•๐Ÿ˜•
hi guys , i am coordinating an event in my collage which is web designing where the participants are supposed to design a dynamic website based on a theme given...
how to compile the servlets program? what should i need for that ? how to run servlet program? how to download tomcat server(actually i visited their site but don't know...
A great site for electronics people is born today!!! Go to you'll be glad for this hint. regards
๐Ÿ˜’ hello, i need a consultant (small and yet experienced) to then place my project within the capable hands of a consultant (large and yet still working prototypes) to achieve...