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

  • SEARCH
  • Home
  • 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 9137199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:04:22+00:00 2026-06-17T09:04:22+00:00

I am trying to sort the columns of a matrix based on the another

  • 0

I am trying to sort the columns of a matrix based on the another vector values in a
fast way in matlab.
Let assume I have a reference vector:

a = [1 8 3];

And the matrix I wanna sort by rows

b =[2 3 4
    5 6 4
    1 2 1];

And I want the result based on the vector a if the sorted a is

 a = [8 3 1]

the sorted matrix will be now

b = [3 4 2 
     6 4 5
     2 1 1];

So the index of the first vector is the same with the index of the columns
So we sort columns based on the values of the vector.

  • 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-17T09:04:22+00:00Added an answer on June 17, 2026 at 9:04 am

    In Matlab the sort function returns two variables, the first is the sorted vector/matrix and the second is a set of indices that can be combined with the original data to produce the sorted values.

    A = [ 5 4 1 2 3 ];
    
    [A_sorted1, idx] = sort(A);
    
    A_sorted2 = A(idx);
    

    A_sorted1 and A_sorted2 are equivalent.

    If the number of rows in b is equal to the number of elements in a then you can simply use:

    [~, idx] = sort(a);
    b_sorted = b(idx,:);
    

    And if you want to sort by columns use:

    b_sorted = b(:,idx);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's said you have a 1D matrix a = rand(1,5); [sa i] = sort(a);
I have a CSV file with many columns. I am trying to sort the
I am trying to sort a list of names followed by another string such
I'm trying to sort by the state of an Organization's main address. I have
I am trying to sort pixel values of an image (example 80x20) from lowest
if i trying to sort my columns return 0 valu. But i need max
I am trying to sort a large (10mb) file on the first 2 columns.
I am trying to sort the search results of a thinking_sphinx search. The columns
I'm trying to sort my dynamic columns in a cross tab according to some
I have a NSTableView with 3 columns. I can sort using any of the

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.