Solve Large Sorted Matrix in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter hoffmann
  • Start date Start date
  • Tags Tags
    Matlab Matrix
Click For Summary
SUMMARY

The discussion focuses on solving the problem of balancing the counts of entries greater than one and those less than or equal to one in a sorted matrix using MATLAB. The provided example matrix is [0 0 0 1 1 1 1 3 3 3 5 6 7 8 9 9], where the user needs to remove the last two entries to achieve the desired balance. The proposed algorithm involves counting entries of two types (A for x ≤ 1 and B for x > 1), iteratively removing the last entry, and checking for equality between the counts of A and B until the condition is met. This method is applicable to larger datasets as well.

PREREQUISITES
  • Understanding of MATLAB programming
  • Familiarity with matrix operations in MATLAB
  • Knowledge of conditional statements and loops in programming
  • Basic algorithm design principles
NEXT STEPS
  • Implement the proposed algorithm in MATLAB using loops and conditional statements
  • Explore MATLAB's built-in functions for matrix manipulation
  • Learn about performance optimization techniques for large datasets in MATLAB
  • Investigate alternative algorithms for balancing counts in sorted matrices
USEFUL FOR

This discussion is beneficial for MATLAB programmers, data analysts, and anyone working with sorted matrices who needs to develop efficient algorithms for data manipulation and analysis.

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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 32 ·
2
Replies
32
Views
4K
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K