What is a Matlab-efficient way (no loop) to do the following operation: transform an input vector input into an output vector output such as output(i) is the number of integers in input that are less or equal than input(i).
For example:
input = [5 3 3 2 4 4 4]
would give:
output = [7 3 3 1 6 6 6]
First of all, don’t use
inputfor a variable name, it’s a reserved keyword. I’ll useXhere instead.An alternative way to obtain your desired result would be:
and here’s a one-liner:
EDIT:
If
Xhas multiple rows and you want to apply this operation on each row, this is a little bit trickier. Here’s what you can do:Example: