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 9018399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:31:03+00:00 2026-06-16T04:31:03+00:00

Possible Duplicate: How can I sort a 2-D array in MATLAB with respect to

  • 0

Possible Duplicate:
How can I sort a 2-D array in MATLAB with respect to one column?
Sort a matrix with another matrix

I have a vector ‘A’ of 429 values and a matrix ‘B’ of 429×200 values. Rows in A and B are share the same indices. My vector ‘A’ contains values 1:1:429 but they are randomly ordered throughout the vector. I want to reorder A so that it indexes in order from 1 to 429 and I also want to sort the rows in matrix ‘B’ in the same order as the newly sorted ‘A’.

Can this be done quick and easy without a for-loop?

Here’s an example to illustrate my point:

A =
    5
    3
    1
    2
    4


 B =
    3   7   0   4   6
    1   2   5   0   8
    4   0   2   0   0
    3   0   1   0   5
    2   2   3   4   4


sortedA = 

1
2
3
4
5

sortedB =

4   0   2   0   0
3   0   1   0   5
1   2   5   0   8
2   2   3   4   4
3   7   0   4   6

Thank you everyone!

  • 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-16T04:31:04+00:00Added an answer on June 16, 2026 at 4:31 am

    The example data:

    A = [ 5, 3, 1, 2, 4 ]';
    
    B = [ 3, 7, 0, 4, 6; 1, 2, 5, 0, 8; 4, 0, 2, 0, 0; 3, 0, 1, 0, 5; 2, 2, 3, 4, 4 ]
    

    Sort the matrices:

    [sortedA,IX] = sort(A);
    
    sortedB = B(IX,:);
    
    sortedA =
     1
     2
     3
     4
     5
    
    sortedB =
     4     0     2     0     0
     3     0     1     0     5
     1     2     5     0     8
     2     2     3     4     4
     3     7     0     4     6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Sort multidimensional Array by Value (2) How can i sort array by
Possible Duplicate: PHP Sort a multidimensional array by element containing date I have some
Possible Duplicate: Sort strings and numbers in Ruby I have an array of place
Possible Duplicate: Can I sort two lists in relation to each other? I have
Possible Duplicate: Ruby: Sorting 2 arrays using values from one of them I have
Possible Duplicate: Using Perl, how can I sort an array using the value of
Possible Duplicate: Can you sort n integers in O(n) amortized complexity? I have to
Possible Duplicate: Array sort function in PHP I have an array like so Array
Possible Duplicate: How do I sort a multidimensional array by one of the fields
Possible Duplicate: Sort multidimensional array by multiple keys I want know how I can

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.