Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8966927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:07:42+00:00 2026-06-15T17:07:42+00:00

What is a Matlab-efficient way (no loop) to do the following operation: transform an

  • 0

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]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:07:43+00:00Added an answer on June 15, 2026 at 5:07 pm

    First of all, don’t use input for a variable name, it’s a reserved keyword. I’ll use X here instead.

    An alternative way to obtain your desired result would be:

    [U, V] = meshgrid(1:numel(X), 1:numel(X));
    Y = sum(X(U) >= X(V))
    

    and here’s a one-liner:

    Y = sum(bsxfun(@ge, X, X'))
    

    EDIT:
    If X has multiple rows and you want to apply this operation on each row, this is a little bit trickier. Here’s what you can do:

    [U, V] = meshgrid(1:numel(X), 1:size(X, 2));
    V = V + size(X, 2) * idivide(U - 1, size(X, 2));
    Xt = X';
    Y = reshape(sum(Xt(U) >= Xt(V))', size(Xt))'
    

    Example:

    X =  
       5   3   3   2   4   4   4
       3   9   7   7   1   2   2
    
    Y = 
       7   3   3   1   6   6   6
       4   7   6   6   1   3   3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple Matlab program that uses a set of random number lists
I need a relatively efficient way to share data between Matlab and R .
What would be the most efficient way to implement a matlab like function to
I currently have the following function, but is there a more efficient way to
I am wondering whether there is an efficient way in MATLAB to generate all
I've stumbled upon the weird way (in my view) that Matlab is dealing with
Is there an efficient implementation of matlab's deconv in python? # Convolve z=conv(x, y)
Matlab documentation states that it is possible to replace the Nth occurrence of the
In MATLAB, how do you write a matrix into an image of EPS format?
I'm trying to find some way to substract a size 3 vector from each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.