Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB help!

  1. Jul 7, 2008 #1
    I have restated my question even further:

    Suppose I have a sorted matrix:

    [ 0 0 0 1 1 1 1 3 3 3 5 6 7 8 9 9 ]

    I need to remove the last value in the matrix until the number of entries that are greater than one equal the number of entries that are either 0 or 1. For the example given above, there are 16 entries. Nine entries are greater than 1 and 7 entries are less than or equal to one. I would need to remove the last two entries such that the number of entries that are greater than one equal the number of entries that are either 0 or 1.

    What if I have a much larger set of values? How do code this in MATLAB?

    Thanks!
     
  2. jcsd
  3. Jul 7, 2008 #2

    zyh

    User Avatar

    I think the algorithm's can be like this:
    1. sum the numbers of type A and type B in your string, for example, type A means if x<=1,and type B means if x>1, and after that, we get the number of A(NoA) and number of B(NoA) in your string.
    2. move the pointer from the last entry,and remove these last entries, and caculate the remaining number of A(RoA) and number of B(RoB), you know, it's very simple to get the number of A and B you removed.
    3. Each time, you remove the last entry and check if RA==RB, then you get the solution.

    I hope you can understand my algorithm.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: MATLAB help!
  1. MATLAB help (Replies: 9)

  2. MATLAB help (Replies: 2)

  3. MATLAB help (Replies: 0)

  4. MATLAB help (Replies: 7)

  5. Matlab help (Replies: 6)

Loading...