CrazyEngineers
  • MATLAB Problem

    sindhya

    sindhya

    @sindhya-OYYUXw
    Updated: Oct 24, 2024
    Views: 967
    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.
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Predictor

    MemberApr 5, 2009

    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
    <a href="https://matlabdatamining.blogspot.com/" target="_blank" rel="nofollow noopener noreferrer">Data Mining in MATLAB</a>
    Are you sure? This action cannot be undone.
    Cancel
  • silverscorpion

    MemberApr 5, 2009

    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.
    Are you sure? This action cannot be undone.
    Cancel
  • Predictor

    MemberApr 5, 2009

    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
    <a href="https://matlabdatamining.blogspot.com/" target="_blank" rel="nofollow noopener noreferrer">Data Mining in MATLAB</a>
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register