MATLAB Problem

sindhya

sindhya

@sindhya-OYYUXw Oct 24, 2024
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

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Predictor

    Predictor

    @predictor-lfVrRm Apr 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>
  • silverscorpion

    silverscorpion

    @silverscorpion-iJKtdQ Apr 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.
  • Predictor

    Predictor

    @predictor-lfVrRm Apr 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>