Solve Large Sorted Matrix in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter hoffmann
  • Start date Start date
  • Tags Tags
    Matlab Matrix
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
hoffmann
Messages
65
Reaction score
0
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!
 
Physics news on Phys.org
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.