Problem 42504. Data Regularization
Provided is an m-by-n integer data matrix A whose elements are drawn arbitrarily from a set S = [1,2,3,...,S] for any large integer number S > 1. The "arbitrary" manner of drawing integer numbers implies that each column of A might contain only a subset of integer numbers from S. Our objective is to regularize the data in A subject to the following rules:
For each column in A,
- The smallest number or numbers (if there are more than one such number) are mapped to 1;
- The 2nd-smallest number or numbers (if there are more than one such number) are mapped to 2;
- The k th-smallest number or numbers (if there are more than one such number) are mapped to k .
For example, S = [1:8] with S = 8. Suppose the input data matrix A is
A = [2 6 5 3 5 6 3 7]
Then the output matrix B is
B = [1 2 3 1 3 2 2 3]
Please try to avoid for or while loops. Vectorized code will be more appreciated.
Solution Stats
Problem Comments
-
3 Comments
without loop makes it quite difficult..is there any particular built-in function to do this?
You do know that Matlab most certainly uses while and for loops to multiply matrices internally. The vectorized solution is probably faster because of parallelization and other optimization tricks, which we could also implement with the proper toolboxes.
And please add an space to strfind, or else It will find fors and whiles inside comments and even parameter names. I was using a parameter "Uniform" of the function cellfun and it took me a while to realize why it was failing the first test.
Solution Comments
Show commentsProblem Recent Solvers38
Suggested Problems
-
Get the length of a given vector
10809 Solvers
-
357 Solvers
-
Determine if input is a perfect number
236 Solvers
-
682 Solvers
-
Spot the First Occurrence of 5
417 Solvers
More from this Author29
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!